Skip to content

Commit

Permalink
8343877: Test AsyncClose.java intermittent fails - Socket.getInputStr…
Browse files Browse the repository at this point in the history
…eam().read() wasn't preempted

Backport-of: 752e1629555f0ec8630373ec87b049afdd709ea6
  • Loading branch information
SendaoYan committed Nov 25, 2024
1 parent 85e4946 commit 3e32b93
Showing 2 changed files with 33 additions and 29 deletions.
32 changes: 17 additions & 15 deletions test/jdk/java/net/Socket/asyncClose/Socket_getInputStream_read.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -60,7 +60,7 @@ public void run() {
}
latch.countDown();
int n = in.read();
failed("Socket.getInputStream().read() returned unexpectedly!!");
failed("Socket.getInputStream().read() returned unexpectedly, n=" + n);
} catch (SocketException se) {
if (latch.getCount() != 1) {
closed();
@@ -77,20 +77,22 @@ public void run() {
public AsyncCloseTest go() {
try {
InetAddress lh = InetAddress.getLocalHost();
ServerSocket ss = new ServerSocket(0, 0, lh);
s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
Socket s2 = ss.accept();
Thread thr = new Thread(this);
thr.start();
latch.await();
Thread.sleep(5000); //sleep, so Socket.getInputStream().read() can block
s.close();
thr.join();
try (ServerSocket ss = new ServerSocket(0, 0, lh)) {
s.connect(new InetSocketAddress(lh, ss.getLocalPort()));
try (Socket s2 = ss.accept()) {
Thread thr = new Thread(this);
thr.start();
latch.await();
Thread.sleep(5000); //sleep, so Socket.getInputStream().read() can block
s.close();
thr.join();
}

if (isClosed()) {
return passed();
} else {
return failed("Socket.getInputStream().read() wasn't preempted");
if (isClosed()) {
return passed();
} else {
return failed("Socket.getInputStream().read() wasn't preempted");
}
}
} catch (Exception x) {
failed(x.getMessage());
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -66,20 +66,22 @@ public void run() {
public AsyncCloseTest go() {
try {
InetAddress lh = InetAddress.getLocalHost();
ServerSocket ss = new ServerSocket(0, 0, lh);
s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
Socket s2 = ss.accept();
Thread thr = new Thread(this);
thr.start();
latch.await();
Thread.sleep(1000);
s.close();
thr.join();
try (ServerSocket ss = new ServerSocket(0, 0, lh)) {
s.connect(new InetSocketAddress(lh, ss.getLocalPort()));
try (Socket s2 = ss.accept()) {
Thread thr = new Thread(this);
thr.start();
latch.await();
Thread.sleep(1000);
s.close();
thr.join();
}

if (isClosed()) {
return passed();
} else {
return failed("Socket.getOutputStream().write() wasn't preempted");
if (isClosed()) {
return passed();
} else {
return failed("Socket.getOutputStream().write() wasn't preempted");
}
}
} catch (Exception x) {
failed(x.getMessage());

0 comments on commit 3e32b93

Please sign in to comment.