-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8287073: NPE from CgroupV2Subsystem.getInstance() #8803
Conversation
👋 Welcome back mkartashev! A progress list of the required criteria for merging this PR into |
@mkartashev The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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.
Can some reviewer take a look at this please ?
This seems to be addressing rare corner issue.
@@ -108,7 +108,7 @@ static CgroupMetrics create() { | |||
Map<String, CgroupInfo> infos = result.getInfos(); | |||
if (result.isCgroupV2()) { | |||
// For unified it doesn't matter which controller we pick. | |||
CgroupInfo anyController = infos.get(MEMORY_CTRL); | |||
CgroupInfo anyController = infos.values().iterator().next(); | |||
CgroupSubsystem subsystem = CgroupV2Subsystem.getInstance(anyController); | |||
return subsystem != null ? new CgroupMetrics(subsystem) : null; |
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.
Looking at implementation of CgroupV2Subsystem.getInstance(...), it seems that it always returns != null ...
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.
CgroupV1Subsystem.getInstance(...)
also claims that it never returns null
, but has a code-path that actually returns null
(when there is no active controller). Is this a possible outcome?
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.
@plevart Are you asking about the reason for the crash or about the changes?
If it's the former, then I believe that the crash comes not from getInstance()
returning null
, but from further down the stack because null
is being passed to getInstance()
. I could be wrong in interpreting the report, though.
If the question's about the changes, then those are restricted to CgroupV2, so I'm not sure how CgroupV1Subsystem.getInstance(...)
returning null is related. FWIW, I also don't think we are going to get here if there are no active controllers. There's this code a few lines above:
if (!result.isAnyControllersEnabled()) {
return null;
}
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.
I was just contemplating the code around the change as it appears to have unnecessary checks which result in dead code. From the point of fixing just this concrete NPE, they are irrelevant. So while this code might benefit from cleanup, perhaps this PR is not the place to do it. Perhaps it is a matter of another issue and 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.
@plevart I think I now understand what you meant and removed the unnecessary checks. Please, have a look.
} else { | ||
CgroupV1Subsystem subsystem = CgroupV1Subsystem.getInstance(infos); | ||
return subsystem != null ? new CgroupV1MetricsImpl(subsystem) : null; | ||
return new CgroupV1MetricsImpl(subsystem); |
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.
This shouldn't be changed because the current implementation of CgroupV1Subsystem.getInstance(infos)
has a path that returns null.
Maybe that's impossible, because when we call CgroupV1Subsystem.getInstance
, we must have at least one v1 subsystem in infos
. However, that's not related to this issue. Please fix that in a separate RFE. For example, CgroupV1Subsystem.getInstance(infos)
can be changed to throw an exception instead if return null.
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.
Fine by me; done.
CgroupSubsystem subsystem = CgroupV2Subsystem.getInstance(anyController); | ||
return subsystem != null ? new CgroupMetrics(subsystem) : null; | ||
return new CgroupMetrics(subsystem); |
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.
Should add Objects.requireNonNull(anyController)
and Objects.requireNonNull(subsystem)
.
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.
I added the first, but not the second as that looks like an overkill; see the definition of the constructor:
CgroupMetrics(CgroupSubsystem subsystem) {
this.subsystem = Objects.requireNonNull(subsystem);
}
@mkartashev This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 97 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@VladimirKempik, @iklam) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@mkartashev |
I tested the patch in our CI pipeline. All container tests passed. |
/sponsor |
@iklam Only the author (@mkartashev) is allowed to issue the |
Going to push as commit 744b822.
Your commit was automatically rebased without conflicts. |
@iklam @mkartashev Pushed as commit 744b822. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Following the logic from the comment directly above the changed line, since it doesn't matter which controller we pick, pick any available controller instead of the one called "memory" specifically. This way we are guarded against getting
null
asanyController
, which is being immediately passed down toCgroupV2Subsystem.getInstance()
that is unprepared to acceptnull
values.It is also worth noting that the previous checks (such as that at line 89) make sure that there exist at least one controller in the map.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8803/head:pull/8803
$ git checkout pull/8803
Update a local copy of the PR:
$ git checkout pull/8803
$ git pull https://git.openjdk.java.net/jdk pull/8803/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 8803
View PR using the GUI difftool:
$ git pr show -t 8803
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8803.diff