提交 3011c0e5 编写于 作者: C chegar

8012244: java/net/Socket/asyncClose/Race.java fails intermittently on Windows

Reviewed-by: alanb, dsamersoff
上级 42643327
......@@ -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;
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;
default:
NET_ThrowCurrent(env, "recv failed");
// 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 WSAETIMEDOUT :
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Read timed out");
break;
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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册