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

8140241: (fc) Data transfer from FileChannel to itself causes hang in case of overlap #5061

Closed

Conversation

@bplb
Copy link
Member

@bplb bplb commented Aug 10, 2021

This request proposes to fix a failure on macOS which occurs when transferring to or from a file channel from or to the same file channel when the source and destination intervals overlap.


Progress

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

Issue

  • JDK-8140241: (fc) Data transfer from FileChannel to itself causes hang in case of overlap

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5061

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

Using diff file

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Aug 10, 2021

👋 Welcome back bpb! 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.

Loading

@bplb
Copy link
Member Author

@bplb bplb commented Aug 10, 2021

This change would work around a bug specific to macOS which the operating system vendor has not fixed in more than five years. The JDK issue was filed in 2015 after having been observed on macOS 10.5.5 (Yosemite); the bug has been observed on macOS versions through 10.15.7 (Catalina).

When run on macOS without the source fix, the included test hangs and its process cannot in general be killed without restarting or in some cases power cycling the machine.

Loading

@openjdk openjdk bot added the rfr label Aug 10, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Aug 10, 2021

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

  • nio

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.

Loading

@openjdk openjdk bot added the nio label Aug 10, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Aug 10, 2021

Loading

@AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Aug 10, 2021

This is logged with Apple as 37764443, it would be useful if we could get an update on that.

I'm not opposed to putting in a workaround for this macOS bug but it does add clutter for a scenario that may not arise too often. If we do put in a workaround then we'll probably need to restructure the overlap checks in both transferToTrustedChannel transferFromFileChannel to avoid overflow. Also transferFrom should check n >= 0 because 0 is a valid return.

Loading

@bplb
Copy link
Member Author

@bplb bplb commented Aug 10, 2021

Fixed the overlap checks and the transferFrom n == 0 case. The scenario is unlikely but if it occurs the consequences are serious. I am trying to find out about the Apple bug (actually 2586576 as the one I filed, 37764443, was marked a duplicate).

Loading

@bplb
Copy link
Member Author

@bplb bplb commented Aug 10, 2021

As an aside, I think that the cast to int at line 689 of FileChannelImpl should have been removed in the fix for JDK-8271308 but was not.

Loading

@AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Aug 10, 2021

As an aside, I think that the cast to int at line 689 of FileChannelImpl should have been removed in the fix for JDK-8271308 but was not.

Including it as part of this change should be okay.

Loading

@AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Aug 10, 2021

Fixed the overlap checks and the transferFrom n == 0 case.

The overlap check looks right now although it is done without the positionLock so the position could potentially change (may not be worth worrying about).

Loading

@bplb
Copy link
Member Author

@bplb bplb commented Aug 10, 2021

The issue is specific to macOS, but the test does not constrain the target platforms. Should it?

Loading

@AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Aug 11, 2021

The issue is specific to macOS, but the test does not constrain the target platforms. Should it?

If it's reliable on all platforms then no reason to restrict it. I think we should at least using try-with-resources in main and generateBigFile so that it closes the file when there is an exception.

Loading

Loading
Loading
@openjdk
Copy link

@openjdk openjdk bot commented Aug 11, 2021

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

8140241: (fc) Data transfer from FileChannel to itself causes hang in case of overlap

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

  • a15b659: 8271732: Regression in StringBuilder.charAt bounds checking
  • ec2fc38: 8272120: Avoid looking for standard encodings in "java." modules
  • bd27bb9: 8272345: macos doesn't check os::set_boot_path() result
  • 44f137f: 8271170: Add unit test for what jpackage app launcher puts in the environment
  • cd2dbe5: 8272328: java.library.path is not set properly by Windows jpackage app launcher
  • 9faab40: 8272330: C2: Cleanup profile counter scaling
  • 75a0642: 8272335: runtime/cds/appcds/MoveJDKTest.java doesn't check exit codes
  • 9ba8a12: 8269774: doclint reports missing javadoc comments for JavaFX properties if the docs are on the property method
  • ec8d3ba: 8271159: [REDO] JDK-8249634 doclint should report implicit constructor as missing javadoc comments
  • 6194227: 8272228: G1: G1CardSetInlinePtr Fix tautological assertion
  • ... and 26 more: https://git.openjdk.java.net/jdk/compare/7fc99cf9b69f99fc78709e57b92cd88e09577d0f...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.

Loading

@openjdk openjdk bot added the ready label Aug 11, 2021
@bplb
Copy link
Member Author

@bplb bplb commented Aug 12, 2021

/integrate

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Aug 12, 2021

Going to push as commit 428d516.
Since your change was applied there have been 42 commits pushed to the master branch:

  • 93cab7d: 8272315: Improve assert_different_registers
  • 9980b41: 8272107: Removal of Unsafe::defineAnonymousClass left a dangling C++ class
  • 464e874: 8048190: NoClassDefFoundError omits original ExceptionInInitializerError
  • 7e14c3c: 8272310: AArch64: Add missing changes for shared vector helper methods in m4 files
  • b29fbad: 8267844: Replace Integer/Long.valueOf() with Integer/Long.parse*() where applicable
  • d38b314: 8272332: --with-harfbuzz=system doesn't add -lharfbuzz after JDK-8255790
  • a15b659: 8271732: Regression in StringBuilder.charAt bounds checking
  • ec2fc38: 8272120: Avoid looking for standard encodings in "java." modules
  • bd27bb9: 8272345: macos doesn't check os::set_boot_path() result
  • 44f137f: 8271170: Add unit test for what jpackage app launcher puts in the environment
  • ... and 32 more: https://git.openjdk.java.net/jdk/compare/7fc99cf9b69f99fc78709e57b92cd88e09577d0f...master

Your commit was automatically rebased without conflicts.

Loading

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

@openjdk openjdk bot commented Aug 12, 2021

@bplb Pushed as commit 428d516.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Loading

@bplb bplb deleted the FileChannel-transferOverlapped-8140241 branch Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants