提交 0208a658 编写于 作者: V vinnie

Merge

...@@ -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
} }
......
...@@ -504,7 +504,7 @@ public class Basic { ...@@ -504,7 +504,7 @@ public class Basic {
cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf1 = supplyAsync(() -> { throw new RuntimeException(); });
cf2 = supplyAsync(() -> 2); cf2 = supplyAsync(() -> 2);
cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 2); return x; }); cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 2); return x; });
try { check(cf3.join() == 1); } catch (CompletionException x) { pass(); } try { check(cf3.join() == 2); } catch (CompletionException x) { pass(); }
check(cf3.isDone()); check(cf3.isDone());
check(cf1.isDone() || cf2.isDone()); check(cf1.isDone() || cf2.isDone());
...@@ -520,6 +520,27 @@ public class Basic { ...@@ -520,6 +520,27 @@ public class Basic {
cf3 = cf1.applyToEitherAsync(cf2, (x) -> { fail(); return x; }); cf3 = cf1.applyToEitherAsync(cf2, (x) -> { fail(); return x; });
checkCompletedExceptionally(cf3); checkCompletedExceptionally(cf3);
check(cf1.isDone() || cf2.isDone()); check(cf1.isDone() || cf2.isDone());
final Phaser cf3Done = new Phaser(2);
cf1 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 1; });
cf2 = supplyAsync(() -> 2);
cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 2); return x; });
checkCompletedNormally(cf3, 2);
checkCompletedNormally(cf2, 2);
check(!cf1.isDone());
cf3Done.arrive();
checkCompletedNormally(cf1, 1);
checkCompletedNormally(cf3, 2);
cf1 = supplyAsync(() -> 1);
cf2 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 2; });
cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1); return x; });
checkCompletedNormally(cf3, 1);
checkCompletedNormally(cf1, 1);
check(!cf2.isDone());
cf3Done.arrive();
checkCompletedNormally(cf2, 2);
checkCompletedNormally(cf3, 1);
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
//---------------------------------------------------------------- //----------------------------------------------------------------
...@@ -570,6 +591,27 @@ public class Basic { ...@@ -570,6 +591,27 @@ public class Basic {
cf3 = cf2.acceptEitherAsync(cf1, (x) -> { fail(); }); cf3 = cf2.acceptEitherAsync(cf1, (x) -> { fail(); });
checkCompletedExceptionally(cf3); checkCompletedExceptionally(cf3);
check(cf1.isDone() || cf2.isDone()); check(cf1.isDone() || cf2.isDone());
final Phaser cf3Done = new Phaser(2);
cf1 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 1; });
cf2 = supplyAsync(() -> 2);
cf3 = cf1.acceptEither(cf2, (x) -> { check(x == 2); });
checkCompletedNormally(cf3, null);
checkCompletedNormally(cf2, 2);
check(!cf1.isDone());
cf3Done.arrive();
checkCompletedNormally(cf1, 1);
checkCompletedNormally(cf3, null);
cf1 = supplyAsync(() -> 1);
cf2 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 2; });
cf3 = cf1.acceptEitherAsync(cf2, (x) -> { check(x == 1); });
checkCompletedNormally(cf3, null);
checkCompletedNormally(cf1, 1);
check(!cf2.isDone());
cf3Done.arrive();
checkCompletedNormally(cf2, 2);
checkCompletedNormally(cf3, null);
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
//---------------------------------------------------------------- //----------------------------------------------------------------
...@@ -605,19 +647,23 @@ public class Basic { ...@@ -605,19 +647,23 @@ public class Basic {
cf1 = runAsync(() -> { throw new RuntimeException(); }); cf1 = runAsync(() -> { throw new RuntimeException(); });
cf2 = runAsync(() -> { }); cf2 = runAsync(() -> { });
cf3 = cf2.runAfterEither(cf1, () -> { atomicInt.incrementAndGet(); }); cf3 = cf2.runAfterEither(cf1, () -> { atomicInt.incrementAndGet(); });
try { check(cf3.join() == null); } catch (CompletionException x) { pass(); } try {
check(cf3.join() == null);
check(atomicInt.get() == (before + 1));
} catch (CompletionException x) { pass(); }
check(cf3.isDone()); check(cf3.isDone());
check(cf1.isDone() || cf2.isDone()); check(cf1.isDone() || cf2.isDone());
check(atomicInt.get() == (before + 1));
before = atomicInt.get(); before = atomicInt.get();
cf1 = runAsync(() -> { }); cf1 = runAsync(() -> { });
cf2 = runAsync(() -> { throw new RuntimeException(); }); cf2 = runAsync(() -> { throw new RuntimeException(); });
cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); }); cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); });
try { check(cf3.join() == null); } catch (CompletionException x) { pass(); } try {
check(cf3.join() == null);
check(atomicInt.get() == (before + 1));
} catch (CompletionException x) { pass(); }
check(cf3.isDone()); check(cf3.isDone());
check(cf1.isDone() || cf2.isDone()); check(cf1.isDone() || cf2.isDone());
check(atomicInt.get() == (before + 1));
before = atomicInt.get(); before = atomicInt.get();
cf1 = runAsync(() -> { throw new RuntimeException(); }); cf1 = runAsync(() -> { throw new RuntimeException(); });
...@@ -626,6 +672,31 @@ public class Basic { ...@@ -626,6 +672,31 @@ public class Basic {
checkCompletedExceptionally(cf3); checkCompletedExceptionally(cf3);
check(cf1.isDone() || cf2.isDone()); check(cf1.isDone() || cf2.isDone());
check(atomicInt.get() == before); check(atomicInt.get() == before);
final Phaser cf3Done = new Phaser(2);
before = atomicInt.get();
cf1 = runAsync(() -> { cf3Done.arriveAndAwaitAdvance(); });
cf2 = runAsync(() -> { });
cf3 = cf1.runAfterEither(cf2, () -> { atomicInt.incrementAndGet(); });
checkCompletedNormally(cf3, null);
checkCompletedNormally(cf2, null);
check(!cf1.isDone());
check(atomicInt.get() == (before + 1));
cf3Done.arrive();
checkCompletedNormally(cf1, null);
checkCompletedNormally(cf3, null);
before = atomicInt.get();
cf1 = runAsync(() -> { });
cf2 = runAsync(() -> { cf3Done.arriveAndAwaitAdvance(); });
cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); });
checkCompletedNormally(cf3, null);
checkCompletedNormally(cf1, null);
check(!cf2.isDone());
check(atomicInt.get() == (before + 1));
cf3Done.arrive();
checkCompletedNormally(cf2, null);
checkCompletedNormally(cf3, null);
} catch (Throwable t) { unexpected(t); } } catch (Throwable t) { unexpected(t); }
//---------------------------------------------------------------- //----------------------------------------------------------------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册