Skip to content
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

JsonSchemaFactory.getSchema not thread safe #891

Closed
mpayne-coveo opened this issue Nov 9, 2023 · 1 comment · Fixed by #892
Closed

JsonSchemaFactory.getSchema not thread safe #891

mpayne-coveo opened this issue Nov 9, 2023 · 1 comment · Fixed by #892

Comments

@mpayne-coveo
Copy link
Contributor

We have a service that uses the same caching mechanism/JsonSchemaFactory to load in JSON schemas, then validate against them as it handles requests in a multithreaded way. Lately, we've been seeing a lot of ConcurrentModificationExceptions when two requests are simultaneously handled and trying to retrieve schemas with the stack trace-

java.util.ConcurrentModificationException: null
	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1221)
	at com.networknt.schema.JsonSchemaFactory.findMetaSchemaForSchema(JsonSchemaFactory.java:350)
	at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:433)
	at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:462)

We're using version 1.0.87 of json-schema-validator. Let me know if you need further details

@mpayne-coveo
Copy link
Contributor Author

The fix, I believe, should be as simple as converting jsonMetaSchemas from a HashMap to a ConcurrentHashMap-

private final Map<String, JsonMetaSchema> jsonMetaSchemas = new HashMap<String, JsonMetaSchema>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant