JENA-2356: Fix race in QueryEngineRegistry, UpdateEngineRegistry init#2047
Merged
afs merged 1 commit intoapache:mainfrom Oct 21, 2023
Merged
JENA-2356: Fix race in QueryEngineRegistry, UpdateEngineRegistry init#2047afs merged 1 commit intoapache:mainfrom
afs merged 1 commit intoapache:mainfrom
Conversation
afs
approved these changes
Oct 21, 2023
Member
|
@shawnsmith Looks good to me. Because initialization is now only in class initialization, it will be thread-safe. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull request Description:
Fix the following exception observed in production:
The root cause is that two threads simultaneously called
QueryEngineRegistry.get()for the first time.At first glance, the old initialization code in
QueryEngineRegistrylooks ok becauseinit()is called during class loading:But if you run the static initialize blocks sequentially, you'll see that things can progress in the following order:
init()and setsregistryto a valid object.registry = null;QueryEngineFactory.get()seesregistry == nulland makes a second call toinit()init()setsregistryto an empty object.init()executes, a concurrent call toQueryEngineFactory.get()seesregistry != nulland tries to use an empty registry.This PR fixes the static call to
init()and removes unnecessary lazy initialization logic fromget().get()would be if some other class didQueryEngineRegistry.registry = null, forcing the class to re-initialize itself. None of the existing Jena code does that but, to be sure, this PR changes thestatic QueryEngineRegistry registryfield toprivate.final. But that's safe only if we can guarantee thatQueryEngineRegistry.init()will never call back intoQueryEngineRegistry.get()via the method calls toQueryEngineMainorQueryEngineFactoryWrapper, and I didn't want to make that assumption. If it's ok to assume that, I'd be happy to update the PR to usefinal.By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.
See the Apache Jena "Contributing" guide.