mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-23 16:55:09 +00:00
8012244: java/net/Socket/asyncClose/Race.java fails intermittently on Windows
Reviewed-by: alanb, dsamersoff
This commit is contained in:
parent
0a5657be1c
commit
dc668d18a3
@ -152,8 +152,9 @@ class DualStackPlainSocketImpl extends AbstractPlainSocketImpl
|
||||
if (!fd.valid())
|
||||
return;
|
||||
|
||||
close0(fdAccess.get(fd));
|
||||
final int nativefd = fdAccess.get(fd);
|
||||
fdAccess.set(fd, -1);
|
||||
close0(nativefd);
|
||||
}
|
||||
|
||||
void socketShutdown(int howto) throws IOException {
|
||||
|
||||
@ -134,32 +134,35 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this,
|
||||
(*env)->SetByteArrayRegion(env, data, off, nread, (jbyte *)bufP);
|
||||
} else {
|
||||
if (nread < 0) {
|
||||
/*
|
||||
* Recv failed.
|
||||
*/
|
||||
switch (WSAGetLastError()) {
|
||||
case WSAEINTR:
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"socket closed");
|
||||
break;
|
||||
// Check if the socket has been closed since we last checked.
|
||||
// This could be a reason for recv failing.
|
||||
if ((*env)->GetIntField(env, fdObj, IO_fd_fdID) == -1) {
|
||||
NET_ThrowSocketException(env, "Socket closed");
|
||||
} else {
|
||||
switch (WSAGetLastError()) {
|
||||
case WSAEINTR:
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||
"socket closed");
|
||||
break;
|
||||
|
||||
case WSAECONNRESET:
|
||||
case WSAESHUTDOWN:
|
||||
/*
|
||||
* Connection has been reset - Windows sometimes reports
|
||||
* the reset as a shutdown error.
|
||||
*/
|
||||
JNU_ThrowByName(env, "sun/net/ConnectionResetException",
|
||||
"");
|
||||
break;
|
||||
case WSAECONNRESET:
|
||||
case WSAESHUTDOWN:
|
||||
/*
|
||||
* Connection has been reset - Windows sometimes reports
|
||||
* the reset as a shutdown error.
|
||||
*/
|
||||
JNU_ThrowByName(env, "sun/net/ConnectionResetException",
|
||||
"");
|
||||
break;
|
||||
|
||||
case WSAETIMEDOUT :
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
|
||||
"Read timed out");
|
||||
break;
|
||||
case WSAETIMEDOUT :
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
|
||||
"Read timed out");
|
||||
break;
|
||||
|
||||
default:
|
||||
NET_ThrowCurrent(env, "recv failed");
|
||||
default:
|
||||
NET_ThrowCurrent(env, "recv failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,8 +23,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8006395
|
||||
* @summary Race in async socket close on Linux
|
||||
* @bug 8006395 8012244
|
||||
* @summary Tests racing code that reads and closes a Socket
|
||||
*/
|
||||
|
||||
import java.io.InputStream;
|
||||
@ -58,7 +58,7 @@ public class Race {
|
||||
Thread.sleep(50);
|
||||
} catch (Exception x) {
|
||||
if (!(x instanceof SocketException
|
||||
&& x.getMessage().equals("Socket closed")))
|
||||
&& x.getMessage().equalsIgnoreCase("socket closed")))
|
||||
x.printStackTrace();
|
||||
// ok, expect Socket closed
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user