Skip to content

Commit 493db4e

Browse files
committed
feat: fix concurrency error
1 parent ccb7715 commit 493db4e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

OpenAi.JsonSchema/Internals/SchemaRefCountVisitor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ public override void Visit(SchemaRootNode schema)
1717
public override void Visit(SchemaRefNode schema)
1818
{
1919
schema.Ref.Count++;
20-
if (_seen.Add(schema.Ref.Value)) {
20+
21+
// System.InvalidOperationException : Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
22+
bool seen;
23+
lock (_seen) {
24+
seen = _seen.Add(schema.Ref.Value);
25+
}
26+
27+
if (seen) {
2128
Visit(schema.Ref.Value);
2229
}
2330
}

0 commit comments

Comments
 (0)