Fix a race condition that leads to ClassAnalyzer with name CdiInjecteeSkippingClassAnalyzer exceptions #6053
+39
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This solves the race condition - keep the effective injectionManager in a thread local. As multiple threads can modify the injectionManager and the
InjectionManagerInjectedCdiTargetinstances are global, effectiveInjectionManager must be scoped to the thread. It's actually scoped to a single WebTarget initialization and removed at the end of the initialization in thedone()method ofCdiComponentProviderThe problem:
A race condition happens when many threads execute REST client call at the same (more specifically, when
WebTarget.request()is called.Symptom:
Occasional
IllegalStateException: Could not find an implementation of ClassAnalyzer with name CdiInjecteeSkippingClassAnalyzerfromWebTarget.requestReason for the exception:
injectionManageris set in the initialization phase, before it's used. It's stored to a shared volatile variable and later picked upinjectionManager, before the original thread uses it, the original thread would use another thread'sinjectionManagerClassAnalyzerclass in time before the first thread uses it, the first thread won't haveClassAnalyzerbean available and throws exceptionA reproducer is described in payara/Payara#7753.
The original fix in Payara fork (53ae843) addresses this by a workaround - a retry in case of exception, which works, because by the next time, the other thread has enough time to bind the
ClassAnalyzerclass. But that solution isn't efficient.(resubmit after #6049)