-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix CommandLine class initialization deadlock. #21608
Conversation
bazelbuild#21566 (comment) shows a deadlock when initializing static variable `CommandLine.EMPTY` and another thread is initializing `CommandLine`'s subclass `AbstractCommandLine` because `CommandLine.EMPTY` is an instance of `AbstractCommandLine`. Fixes bazelbuild#21566.
@benjaminp Thanks so much for the fix! /cc @justinhorvitz Looks like the bug was introduced in b82dcdc |
@benjaminp thank you so much for the diagnosis and fix. Unfortunately we've already released the culprit change inside google yesterday and are seeing impact, but this PR allowed us to figure out the user complaints of stuck builds and start working on getting the fix released. |
#21566 (comment) shows a deadlock when initializing static variable `CommandLine.EMPTY` and another thread is initializing `CommandLine`'s subclass `AbstractCommandLine` because `CommandLine.EMPTY` is an instance of `AbstractCommandLine`. Fixes #21566. Closes #21608. PiperOrigin-RevId: 613736999 Change-Id: Iadb738b0a89f34cee9a03bc92b385fa7ab58c98f
As a followup, I submitted a bug report to Intellij because the code inspections did not catch this: https://youtrack.jetbrains.com/issue/IDEA-348744/Static-initializer-references-subclass-inspection-doesnt-report-private-class. The irony is that initially I did get such a warning, but then rearranged the code to make the warning go away. |
I've run into this type of issue a few times. It's surely one of darkest corners of the JVM especially given the superficial innocuousness of the code that unlocks deadlock gremlins in production. At least maybe this episode will yield better IDE and errorprone checks! IMO, hotspot should also have runtime deadlock detector for this issue. Static analysis cannot detect every case of the deadlock, and a "nice" JVM crash usually beats a hung process. |
#21566 (comment) shows a deadlock when initializing static variable
CommandLine.EMPTY
and another thread is initializingCommandLine
's subclassAbstractCommandLine
becauseCommandLine.EMPTY
is an instance ofAbstractCommandLine
.Fixes #21566.