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

8240349: jlink should not leave partial image output directory on failure #4386

Closed
wants to merge 2 commits into from
Closed

8240349: jlink should not leave partial image output directory on failure #4386

wants to merge 2 commits into from

Conversation

sundararajana
Copy link
Member

@sundararajana sundararajana commented Jun 7, 2021

jlink should clean up output directory on any failure. should not leave partially filled output.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8240349: jlink should not leave partial image output directory on failure

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4386/head:pull/4386
$ git checkout pull/4386

Update a local copy of the PR:
$ git checkout pull/4386
$ git pull https://git.openjdk.java.net/jdk pull/4386/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4386

View PR using the GUI difftool:
$ git pr show -t 4386

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4386.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jun 7, 2021

👋 Welcome back sundar! 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 label Jun 7, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jun 7, 2021

@sundararajana 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 label Jun 7, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Jun 7, 2021

Webrevs

@openjdk
Copy link

@openjdk openjdk bot commented Jun 7, 2021

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

8240349: jlink should not leave partial image output directory on failure

Reviewed-by: jlaskey, alanb

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 56 new commits pushed to the master branch:

  • 07108c9: 8268241: deprecate JVM TI Heap functions 1.0
  • c9dbc4f: 8266891: Provide a switch to force the class space to a specific location
  • 2cc1977: 8268424: JFR tests fail due to GC cause 'G1 Preventive Collection' not in the valid causes after JDK-8257774
  • 58a59e3: 8240997: Remove more "hack" word in security codes
  • 1c3932f: 8264766: ClassCastException during template compilation (Variable cannot be cast to Param)
  • f6f82c3: 8266421: Deadlock in Sound System
  • bcaa2cb: 8264144: Add handling of "--about-url" CLI parameter for RPM/DEB packages
  • ae16052: 8268088: Clarify Method::clear_jmethod_ids() related comments in ClassLoaderData::~ClassLoaderData()
  • 5ad4a91: 8268127: Shenandoah: Heap size may be too small for region to align to large page size
  • 7a37816: 8264866: Remove unneeded WorkArounds.isAutomaticModule
  • ... and 46 more: https://git.openjdk.java.net/jdk/compare/b05fa02e7413fdcc40969645309e3e9d4442c78d...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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Jun 7, 2021
Copy link
Contributor

@AlanBateman AlanBateman left a comment

I think we need to rename the JBS issue as this is not specific to the -vm option. Instead, this is about cleanup when jlink fails with some intermediate files in the output directory.

@@ -468,6 +486,30 @@ public static ModuleFinder newModuleFinder(List<Path> paths,
return finder;
}

private static void deleteDirectory(Path dir) throws IOException {
if (dir != null && Files.isDirectory(dir)) {
Copy link
Contributor

@AlanBateman AlanBateman Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this method should be checking dir, that should be up to the caller to ensure that it is not called when output is null.

Copy link
Member Author

@sundararajana sundararajana Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. will move that check to caller.

@JornVernee
Copy link
Member

@JornVernee JornVernee commented Jun 8, 2021

WRT the test failure on Windows discussed offline: when the directory is deleted as a result of a PluginException being thrown, there is still an open file handle on the lib/modules file in the image directory, which prevents the directory from being deleted.

Bisecting this, it seems that the file handle is being created in ImageFileCreater::writeImage with a call to plugins.getJImageFileOutputStream (https://github.com/openjdk/jdk/blob/master/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java#L162). This creates an output stream that is never closed.

Following patch fixes:

diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
index 749025bea9d..8beddc5a037 100644
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
@@ -158,8 +158,10 @@ public final class ImageFileCreator {
         BasicImageWriter writer = new BasicImageWriter(byteOrder);
         ResourcePoolManager allContent = createPoolManager(archives,
                 entriesForModule, byteOrder, writer);
-        ResourcePool result = generateJImage(allContent,
-             writer, plugins, plugins.getJImageFileOutputStream());
+        ResourcePool result;
+        try (DataOutputStream out = plugins.getJImageFileOutputStream()) {
+            result = generateJImage(allContent, writer, plugins, out);
+        }

         //Handle files.
         try {

@sundararajana
Copy link
Member Author

@sundararajana sundararajana commented Jun 8, 2021

WRT the test failure on Windows discussed offline: when the directory is deleted as a result of a PluginException being thrown, there is still an open file handle on the lib/modules file in the image directory, which prevents the directory from being deleted.

Bisecting this, it seems that the file handle is being created in ImageFileCreater::writeImage with a call to plugins.getJImageFileOutputStream (https://github.com/openjdk/jdk/blob/master/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java#L162). This creates an output stream that is never closed.

Following patch fixes:

diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
index 749025bea9d..8beddc5a037 100644
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java
@@ -158,8 +158,10 @@ public final class ImageFileCreator {
         BasicImageWriter writer = new BasicImageWriter(byteOrder);
         ResourcePoolManager allContent = createPoolManager(archives,
                 entriesForModule, byteOrder, writer);
-        ResourcePool result = generateJImage(allContent,
-             writer, plugins, plugins.getJImageFileOutputStream());
+        ResourcePool result;
+        try (DataOutputStream out = plugins.getJImageFileOutputStream()) {
+            result = generateJImage(allContent, writer, plugins, out);
+        }

         //Handle files.
         try {

Thanks @JornVernee

@sundararajana sundararajana changed the title 8240349: jlink --vm with not present VM does not fail fast 8240349: jlink should not leave partial image output directory on failure Jun 8, 2021
…directory should not be deleted when exiting.
Copy link
Contributor

@AlanBateman AlanBateman left a comment

New version looks good.

Good spot by Jorn that ImageFileCreator wasn't closing.

@sundararajana
Copy link
Member Author

@sundararajana sundararajana commented Jun 9, 2021

/integrate

@openjdk openjdk bot closed this Jun 9, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Jun 9, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jun 9, 2021

@sundararajana Since your change was applied there have been 56 commits pushed to the master branch:

  • 07108c9: 8268241: deprecate JVM TI Heap functions 1.0
  • c9dbc4f: 8266891: Provide a switch to force the class space to a specific location
  • 2cc1977: 8268424: JFR tests fail due to GC cause 'G1 Preventive Collection' not in the valid causes after JDK-8257774
  • 58a59e3: 8240997: Remove more "hack" word in security codes
  • 1c3932f: 8264766: ClassCastException during template compilation (Variable cannot be cast to Param)
  • f6f82c3: 8266421: Deadlock in Sound System
  • bcaa2cb: 8264144: Add handling of "--about-url" CLI parameter for RPM/DEB packages
  • ae16052: 8268088: Clarify Method::clear_jmethod_ids() related comments in ClassLoaderData::~ClassLoaderData()
  • 5ad4a91: 8268127: Shenandoah: Heap size may be too small for region to align to large page size
  • 7a37816: 8264866: Remove unneeded WorkArounds.isAutomaticModule
  • ... and 46 more: https://git.openjdk.java.net/jdk/compare/b05fa02e7413fdcc40969645309e3e9d4442c78d...master

Your commit was automatically rebased without conflicts.

Pushed as commit 4d1cf51.

💡 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 integrated
4 participants