Closed jack-ohara closed 4 years ago
Thanks for the report and the sample test. I'll add it to the suite so I can fix the problem.
I find it odd that there's no $recursiveRef
in your schema, yet this is the keyword that's throwing. That leads me to believe it's happening in the meta-schema validation, but that's not part of the stack trace.
It looks like it is from the MetaSchema Validation. The part of the trace in VocabularyKeyword is line 127. I'm guessing the issue is that the meta schemas are shared and are coming from a static ConcurrentDictionary.
Hm..., yeah it's here: https://github.com/gregsdennis/Manatee.Json/blob/master/Manatee.Json/Schema/Keywords/RecursiveRefKeyword.cs#L72
So this keyword instance is on the metaschema, which is attempting to validate concurrently. This particular array is used to detect recursive loops in the schema by storing the instance locations that it's already evaluated.
Even if it didn't throw an exception, it's still not thread-safe because it could store a location from evaluating that same location on another instance on another thread.
I have a few solutions in mind. I'll play with those and see what comes of them.
@gregsdennis thanks for the fix! 👍
Just came across this bug while validating the schema and validating objects in another test case.
Went to file an issue but was delighted to find it already fixed 👍. Thanks!
FWIW -- I've come across similar issues in other JSON Schema evaluators, and have come to the conclusion that storing any sort of state information right in the schema structure is a Bad Idea with the potential to create all kinds of hidden bugs, and so have switched to storing state info in an out-of-band structure that only the current evaluator instance has access to in its own thread.
Describe the bug We have individual tests which check two separate APIs return a result that adheres to the same schema. When these tests are run in parallel, the
ValidateSchema()
method throws an exception. The exception is either of the below:To Reproduce I have written a unit test that reproduces the error:
The schema I was using for this test is:
Expected behavior The schema should be validated successfully on all threads.
Desktop (please complete the following information):