提交 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,9 +134,11 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this, ...@@ -134,9 +134,11 @@ 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) {
NET_ThrowSocketException(env, "Socket closed");
} else {
switch (WSAGetLastError()) { switch (WSAGetLastError()) {
case WSAEINTR: case WSAEINTR:
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
...@@ -163,6 +165,7 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this, ...@@ -163,6 +165,7 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this,
} }
} }
} }
}
if (bufP != BUF) { if (bufP != BUF) {
free(bufP); free(bufP);
} }
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册