提交 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 ...@@ -152,8 +152,9 @@ class DualStackPlainSocketImpl extends AbstractPlainSocketImpl
if (!fd.valid()) if (!fd.valid())
return; return;
close0(fdAccess.get(fd)); final int nativefd = fdAccess.get(fd);
fdAccess.set(fd, -1); fdAccess.set(fd, -1);
close0(nativefd);
} }
void socketShutdown(int howto) throws IOException { void socketShutdown(int howto) throws IOException {
......
...@@ -134,32 +134,35 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this, ...@@ -134,32 +134,35 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this,
(*env)->SetByteArrayRegion(env, data, off, nread, (jbyte *)bufP); (*env)->SetByteArrayRegion(env, data, off, nread, (jbyte *)bufP);
} else { } else {
if (nread < 0) { if (nread < 0) {
/* // Check if the socket has been closed since we last checked.
* Recv failed. // This could be a reason for recv failing.
*/ if ((*env)->GetIntField(env, fdObj, IO_fd_fdID) == -1) {
switch (WSAGetLastError()) { NET_ThrowSocketException(env, "Socket closed");
case WSAEINTR: } else {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", switch (WSAGetLastError()) {
"socket closed"); case WSAEINTR:
break; JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"socket closed");
case WSAECONNRESET: break;
case WSAESHUTDOWN:
/* case WSAECONNRESET:
* Connection has been reset - Windows sometimes reports case WSAESHUTDOWN:
* the reset as a shutdown error. /*
*/ * Connection has been reset - Windows sometimes reports
JNU_ThrowByName(env, "sun/net/ConnectionResetException", * the reset as a shutdown error.
""); */
break; JNU_ThrowByName(env, "sun/net/ConnectionResetException",
"");
case WSAETIMEDOUT : break;
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Read timed out"); case WSAETIMEDOUT :
break; JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Read timed out");
default: break;
NET_ThrowCurrent(env, "recv failed");
default:
NET_ThrowCurrent(env, "recv failed");
}
} }
} }
} }
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
/* /*
* @test * @test
* @bug 8006395 * @bug 8006395 8012244
* @summary Race in async socket close on Linux * @summary Tests racing code that reads and closes a Socket
*/ */
import java.io.InputStream; import java.io.InputStream;
...@@ -58,7 +58,7 @@ public class Race { ...@@ -58,7 +58,7 @@ public class Race {
Thread.sleep(50); Thread.sleep(50);
} catch (Exception x) { } catch (Exception x) {
if (!(x instanceof SocketException if (!(x instanceof SocketException
&& x.getMessage().equals("Socket closed"))) && x.getMessage().equalsIgnoreCase("socket closed")))
x.printStackTrace(); x.printStackTrace();
// ok, expect Socket closed // ok, expect Socket closed
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册