Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

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 ...

Copy link
Contributor

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?

Copy link
Member Author

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;
}

Copy link
Contributor

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.

Copy link
Member Author

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 {
Expand Down