-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation is not thread safe #80
Comments
jsonschema isn't thread-safe, qri-io/jsonschema#80, so this adds a lock around the part that accesses a package level variable so that we can use it in goroutines. Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Do you know what type of fix you would accept as a PR? I had to workaround this, and ended up making the keyword registry a struct so that after it's constructed, you aren't modifying a package variable anymore. The solution does use locks though in order to preserve the original API. I can submit a PR if that solution seems okay to you. |
The schema registry might suffer from the same problem. Would it be viable to make both Was looking into @carolynvs fix, and seems to be a step in the right direction, although the keywordRegistry still is globally scoped. |
Yeah sorry my fix wasn't everything that is necessary to address the problem. It was just enough to fix the code paths that we use for our project. |
@Arqu Is @carolynvs implementation what you were thinking as a solution to this ticket? I'm in need of a solution to this, and willing to work on it. Any concerns or suggestions that help on such PR being accepted are more than welcome. |
I'm not too sure of all the details we will have to deal with on this front, however the shortest path there that I see would be to wrap the initialization of a schema ( |
Thank you for looking into this! I would like to highlight that some other data structures in the jsonschema package are also not thread safe: we have recently encountered an issue with
A higher-level cnab-go example triggering the same issue:
|
@dataoleg Porter is using a fork of this library with a fix for that. Here is the open PR to cnab-go and the fork. cnab-go was reluctant to use my patch because it won't be accepted upstream in this repo. If there is another person needing the patch besides Porter, maybe that is enough support to get it merged into cnab-go until a better fix is available. |
I have submitted a PR with the patch we have been using in cnab and porter. #103 I'm not sure this is what you were looking for, but maybe it can get us thinking about a solution. |
#103 has been merged. It doesn't completely fix all thread-safety concerns but it does make calls to Validate and RegisterKeyword safe. |
Unfortunately Validate is not completly thread-safe yet. I found at least one more problem calling ValidateBytes.
|
The current implementation is not thread safe (mostly due to the global schema registry) and should be improved.
Known reports: #76 (comment)
The text was updated successfully, but these errors were encountered: