-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Avoid static dependency from TermsEnum to one of its subclasses #15319
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
Conversation
|
This PR does not have an entry in lucene/CHANGES.txt. Consider adding one. If the PR doesn't need a changelog entry, then add the skip-changelog label to it and you will stop receiving this reminder on future updates to the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. Vicious. I liked the static before-everything initializer that you mentioned - this was explicit and could be documented appropriately as to why it's there. This solution is also fine although I'm a bit worried that, over time, somebody (or some-ai-thing) may have an idea to refactor it back to remove duplicated code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for this fix.
I think there's a possible static detector for this: https://errorprone.info/bugpattern/ClassInitializationDeadlock
Unfortunately the lint is disabled right now, will take a look into it separately and see if we can turn it on / fix others.
A manual test can detect this trivially, but it needs to run independently so that it can effectively control the order of which classes get loaded, so is not really suited to our testing infrastructure. I think the static detector that Robert mentioned above is the way to prevent these things creeping back in. |
|
What I meant was this - but maybe it's too much voodoo. |
Yeah, I consider it too much voodoo to add in our source base, given that the source code change is so trivial. I add a comment in the code which notes to not refactor this class in such a way that can break things. This should be enough until we get the static analysis. My primary motivation for mentioning the voodoo workaround is to help users of Lucene if they run into this problem - until we can get the fix into 10.4. For example, we've seen this deadlock several times in Elasticsearch, but only coming to my attention now. So we'll apply the voodoo workaround there until the next 10.x release. |
|
Now i remember why this check isn't enabled. it is exactly as the comment states, some real work. The first error you see from the check against Unfortunately, there are 82 errors in |
|
best thought i have is to |
oh boy! this is quite a bit more than I would have expected! :-( |
|
it turned out to just be "multiplied" by the code generator: not that many unique violations: #15322 |
Fixes a potential hang with initialisation of TermsEnum and BaseTermsEnum, by simply removing the dependency and replicating the small amount of code. Problem description: the static TermsEnum.EMPTY initialises to an implementation of BaseTermsEnum. TermsEnum is a superclass of BaseTermsEnum, so there is a clear dependency between these classes. If a subclass of BaseTermsEnum is initialising it may grab the lock on BaseTermsEnum, and prevent TermsEnum from initialising. --------- Co-authored-by: Robert Muir <[email protected]>
Fixes a potential hang with initialisation of TermsEnum and BaseTermsEnum, by simply removing the dependency and replicating the small amount of code.
Problem description: the static
TermsEnum.EMPTYinitialises to an implementation ofBaseTermsEnum.TermsEnumis a superclass ofBaseTermsEnum, so there is a clear dependency between these classes. If a subclass ofBaseTermsEnumis initialising it may grab the lock onBaseTermsEnum, and preventTermsEnumfrom initialising. E.g.fixes #15317