Skip to content

8317801: java/net/Socket/asyncClose/Race.java fails intermittently (aix)#4294

Open
shruacha1234 wants to merge 3 commits intoopenjdk:masterfrom
shruacha1234:backport_8f121a17
Open

8317801: java/net/Socket/asyncClose/Race.java fails intermittently (aix)#4294
shruacha1234 wants to merge 3 commits intoopenjdk:masterfrom
shruacha1234:backport_8f121a17

Conversation

@shruacha1234
Copy link
Contributor

@shruacha1234 shruacha1234 commented Mar 15, 2026

This pull request contains a backport of commit 8f121a17 from the openjdk/jdk repository.
OpenJDK bug : https://bugs.openjdk.org/browse/JDK-8317801

This fix resolves a race condition in socket close handling that led to intermittent failures in Race.java on AIX in JDK17u-dev

The original patch didn’t apply cleanly to the JDK17u-dev branch due to differences in the NIO dispatcher implementation:

  • UnixDispatcher introduced in later JDK versions does not exist in JDK17.
  • Virtual thread related logic in the original patch is not present in JDK17.
  • The dispatcher hierarchy differs slightly.

To adapt the change for JDK17:

  • NativeDispatcher.preClose was updated to accept the reader and writer thread IDs.
  • Thread signalling logic was moved into FileDispatcherImpl.
  • Channel implementations (SocketChannelImpl, DatagramChannelImpl, ServerSocketChannelImpl, etc.) were updated to delegate signalling through the dispatcher rather than performing it locally.

These changes preserve the functional intent of the upstream patch, ensuring that threads blocked in I/O operations are correctly signalled when a file descriptor is pre-closed.

Testing : local AIX build, java_io, java_nio, jdk_net
Additionally, executed java/net/Socket/asyncClose/Race.java 500 times to check for intermittent failures. No failures were observed.


Progress

  • Change must not contain extraneous whitespace
  • JDK-8317801 needs maintainer approval
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 2 Reviewers)

Issue

  • JDK-8317801: java/net/Socket/asyncClose/Race.java fails intermittently (aix) (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk17u-dev.git pull/4294/head:pull/4294
$ git checkout pull/4294

Update a local copy of the PR:
$ git checkout pull/4294
$ git pull https://git.openjdk.org/jdk17u-dev.git pull/4294/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4294

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk17u-dev/pull/4294.diff

Using Webrev

Link to Webrev Comment

Signed-off-by: Shruthi <Shruthi.Shruthi1@ibm.com>
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 15, 2026

👋 Welcome back sacharya! 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
Copy link

openjdk bot commented Mar 15, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title Backport 8f121a173ca2534c706682f6c68fbbb0b94ec057 8317801: java/net/Socket/asyncClose/Race.java fails intermittently (aix) Mar 15, 2026
@openjdk
Copy link

openjdk bot commented Mar 15, 2026

This backport pull request has now been updated with issue from the original commit.

@openjdk openjdk bot added backport Port of a pull request already in a different code base rfr Pull request is ready for review labels Mar 15, 2026
@mlbridge
Copy link

mlbridge bot commented Mar 15, 2026

Webrevs

@jerboaa
Copy link
Contributor

jerboaa commented Mar 16, 2026

This backport is being done very differently in JDK 17u because for JDK 21u the following dependencies where included first in the JDK 21 release before doing the actual backport for this bug:

It would have helped if this information was provided to the reader. If we end up going this route without the enhancement backports (which should be fine IMO), then we should more accurately model it to pre-existing JDK 17u code. A review follows shortly.

Comment on lines +63 to +64
FileDispatcherImpl dispatcher = new FileDispatcherImpl();
dispatcher.preClose(fd, reader, writer);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just delegate to FileDispatcherImpl as before:

Suggested change
FileDispatcherImpl dispatcher = new FileDispatcherImpl();
dispatcher.preClose(fd, reader, writer);
FileDispatcherImpl.preClose(fd, reader, writer);

Copy link
Contributor

Choose a reason for hiding this comment

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

In order to avoid the name clash with the non-static variant use a name other than preClose. E.g. doPreClose

@jerboaa
Copy link
Contributor

jerboaa commented Mar 16, 2026

/reviewers 2 Reviewer

@openjdk
Copy link

openjdk bot commented Mar 16, 2026

@jerboaa
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 2 Reviewers).

Signed-off-by: Shruthi <Shruthi.Shruthi1@ibm.com>
Signed-off-by: Shruthi <Shruthi.Shruthi1@ibm.com>
Copy link
Contributor

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

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

The build failure should be resolved in a different way (rename the shared static method).

}

void implPreClose(FileDescriptor fd, long reader, long writer) throws IOException {
static void implPreClose(FileDescriptor fd, long reader, long writer) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it private, please. Or fold it into doPreClose

* dup'ed to a special fd and the thread signalled so that the syscall fails with EINTR.
*/
final void preClose(FileDescriptor fd, long reader, long writer) throws IOException {
static final void preClose(FileDescriptor fd, long reader, long writer) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

static void doPreClose(...)

Also, please add a comment similar to the the one that was added in preClose0 (and remove the one for preClose0 as it's now outdated:

    // Shared with SocketDispatcher and DatagramDispatcher

preClose0 is only used in this class now, so should be private.

Comment on lines +63 to +64
FileDispatcherImpl dispatcher = new FileDispatcherImpl();
dispatcher.preClose(fd, reader, writer);
Copy link
Contributor

Choose a reason for hiding this comment

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

In order to avoid the name clash with the non-static variant use a name other than preClose. E.g. doPreClose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Port of a pull request already in a different code base rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants