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

Conversation

mkartashev
Copy link
Member

@mkartashev mkartashev commented May 20, 2022

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 as anyController, which is being immediately passed down to CgroupV2Subsystem.getInstance() that is unprepared to accept null 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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8287073: NPE from CgroupV2Subsystem.getInstance()

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

@bridgekeeper
Copy link

bridgekeeper bot commented May 20, 2022

👋 Welcome back mkartashev! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 20, 2022
@openjdk
Copy link

openjdk bot commented May 20, 2022

@mkartashev The following label will be automatically applied to this pull request:

  • core-libs

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.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label May 20, 2022
@mlbridge
Copy link

mlbridge bot commented May 20, 2022

Webrevs

Copy link

@VladimirKempik VladimirKempik left a 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;
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 {
CgroupV1Subsystem subsystem = CgroupV1Subsystem.getInstance(infos);
return subsystem != null ? new CgroupV1MetricsImpl(subsystem) : null;
return new CgroupV1MetricsImpl(subsystem);
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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

Copy link
Member Author

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

@openjdk
Copy link

openjdk bot commented May 26, 2022

@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:

8287073: NPE from CgroupV2Subsystem.getInstance()

Reviewed-by: vkempik, iklam

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 master branch:

  • 176bb23: 8287200: Test java/lang/management/ThreadMXBean/VirtualThreadDeadlocks.java timed out after JDK-8287103
  • ec97da9: 8287352: DockerTestUtils::execute shows incorrect elapsed time
  • 140419f: 8286058: AArch64: clarify types of calls
  • 6a33974: 8286737: Test vmTestbase/gc/gctests/WeakReference/weak006/weak006.java fails: Last soft reference has not been cleared
  • 295be6f: 8287285: Avoid redundant HashMap.containsKey call in java.util.zip.ZipFile.Source.get
  • 7cb368b: 8286709: (fc) FileChannel/FileChannelImpl cleanup
  • 7eb1559: 8286045: Use ForceGC for cleaner test cases
  • e44465d: 8287336: GHA: Workflows break on patch versions
  • c10749a: 8287187: Utilize HashMap.newHashMap() in CLDRConverter
  • f235955: 8287246: DSAKeyValue should check for missing params instead of relying on KeyFactory provider
  • ... and 87 more: https://git.openjdk.java.net/jdk/compare/d5d19f52ceb1430104b12a42c78489f42477a9b0...master

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 in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 26, 2022
@mkartashev
Copy link
Member Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label May 27, 2022
@openjdk
Copy link

openjdk bot commented May 27, 2022

@mkartashev
Your change (at version 9e6c0f3) is now ready to be sponsored by a Committer.

@iklam
Copy link
Member

iklam commented May 30, 2022

I tested the patch in our CI pipeline. All container tests passed.
/integrate

@iklam
Copy link
Member

iklam commented May 30, 2022

/sponsor

@openjdk
Copy link

openjdk bot commented May 30, 2022

@iklam Only the author (@mkartashev) is allowed to issue the integrate command. As this pull request is ready to be sponsored, and you are an eligible sponsor, did you mean to issue the /sponsor command?

@openjdk
Copy link

openjdk bot commented May 30, 2022

Going to push as commit 744b822.
Since your change was applied there have been 114 commits pushed to the master branch:

  • 5848a60: 8286093: java/awt/geom/Path2D/UnitTest.java failed with "RuntimeException: 2D bounds too small"
  • 3d2d039: 8287440: Typo in package-info.java of java.util.random
  • 36350bf: 8287484: JFR: Seal RecordedObject
  • a6e2e22: 8285008: JFR: jdk/jfr/jmx/streaming/TestClose.java failed with "Exception: Expected repository to be empty"
  • 2c461ac: 8287492: ProblemList compiler/jvmci/errors/TestInvalidDebugInfo.java
  • 6634037: 8287362: FieldAccessWatch testcase failed on AIX platform
  • 410a25d: 8286562: GCC 12 reports some compiler warnings
  • ed8e8ac: 8284400: Improve XPath exception handling
  • d3e781d: 8287223: C1: Inlining attempt through MH::invokeBasic() with null receiver
  • 0df4748: 8287463: JFR: Disable TestDevNull.java on Windows
  • ... and 104 more: https://git.openjdk.java.net/jdk/compare/d5d19f52ceb1430104b12a42c78489f42477a9b0...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 30, 2022
@openjdk openjdk bot closed this May 30, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels May 30, 2022
@openjdk
Copy link

openjdk bot commented May 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants