Skip to content

Pattern cache is not thread safe #45

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

Closed
marcust opened this issue Mar 19, 2021 · 3 comments
Closed

Pattern cache is not thread safe #45

marcust opened this issue Mar 19, 2021 · 3 comments

Comments

@marcust
Copy link

marcust commented Mar 19, 2021

I just had that thrown in my face:

java.util.ConcurrentModificationException: null
	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1225)
	at graphql.validation.constraints.standard.PatternConstraint.cachedPattern(PatternConstraint.java:86)
	at graphql.validation.constraints.standard.PatternConstraint.runConstraint(PatternConstraint.java:74)
	at graphql.validation.constraints.AbstractDirectiveConstraint.runConstraintOnDirectives(AbstractDirectiveConstraint.java:155)
	at graphql.validation.constraints.AbstractDirectiveConstraint.runValidationImpl(AbstractDirectiveConstraint.java:136)
	at graphql.validation.constraints.AbstractDirectiveConstraint.runValidation(AbstractDirectiveConstraint.java:127)
	at graphql.validation.rules.TargetedValidationRules.runValidationImpl(TargetedValidationRules.java:131)
	at graphql.validation.rules.TargetedValidationRules.walkObjectArg(TargetedValidationRules.java:181)
	at graphql.validation.rules.TargetedValidationRules.runValidationImpl(TargetedValidationRules.java:147)
	at graphql.validation.rules.TargetedValidationRules.runValidationRules(TargetedValidationRules.java:121)
	at graphql.validation.schemawiring.FieldValidatorDataFetcher.get(FieldValidatorDataFetcher.java:47)

this is due to this in my schema

    country: String! @Pattern(regexp: "[A-Z][A-Z]")

and as we are running our tests in parallel that might actually happen that it is hit twice by different threads. I guess in real life that does not happen because you will not have so many requests hit at once without any warming up period which makes the pattern be cached already, but still.

If you have static maps, they should be thread safe.

@dwybourn
Copy link

We're running into this same issue, is there any work around for this?

@heowc
Copy link
Contributor

heowc commented Apr 27, 2022

This issue was addressed by #65

@dondonz
Copy link
Member

dondonz commented Nov 13, 2022

Closing as #65 has been merged

@dondonz dondonz closed this as completed Nov 13, 2022
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

No branches or pull requests

4 participants