Skip to content
Permalink
Browse files
8129310: java/net/Socket/asyncClose/AsyncClose.java fails intermittently
Backport-of: fb6de4b
  • Loading branch information
RealCLanger committed Sep 20, 2021
1 parent 86cd9ba commit 8a2cb87148aad4c4ab4f04cb1dd7b6a52df0b392
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -36,19 +36,20 @@ public synchronized boolean hasPassed() {
}

protected synchronized AsyncCloseTest passed() {
if (reason == null)
if (failureReason() == null) {
passed = true;
}
return this;
}

protected synchronized AsyncCloseTest failed(String r) {
passed = false;
reason = r;
reason.append(String.format("%n - %s", r));
return this;
}

public synchronized String failureReason() {
return reason;
return reason.length() > 0 ? reason.toString() : null;
}

protected synchronized void closed() {
@@ -60,6 +61,6 @@ protected synchronized boolean isClosed() {
}

private boolean passed;
private String reason;
private final StringBuilder reason = new StringBuilder();
private boolean closed;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@ public DatagramSocket_receive() throws SocketException {
public DatagramSocket_receive(int timeout) throws SocketException {
this.timeout = timeout;
latch = new CountDownLatch(1);
s = new DatagramSocket();
s = new DatagramSocket(0, InetAddress.getLoopbackAddress());
}

public String description() {
@@ -60,7 +60,7 @@ public void run() {
}
latch.countDown();
s.receive(p);
failed("DatagramSocket.receive(DatagramPacket) returned unexpectly!!");
failed("DatagramSocket.receive(DatagramPacket) returned unexpectly!!" + " - " + p.getAddress());
} catch (SocketException se) {
if (latch.getCount() != 1) {
closed();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@ public ServerSocket_accept() throws IOException {
public ServerSocket_accept(int timeout) throws IOException {
this.timeout = timeout;
latch = new CountDownLatch(1);
ss = new ServerSocket(0);
ss = new ServerSocket(0, 0, InetAddress.getLoopbackAddress());
}

public String description() {
@@ -56,7 +56,7 @@ public void run() {
try {
latch.countDown();
Socket s = ss.accept();
failed("ServerSocket.accept() returned unexpectly!!");
failed("ServerSocket.accept() returned unexpectly!!" + " - " + s);
} catch (SocketException se) {
closed();
} catch (Exception e) {

1 comment on commit 8a2cb87

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 8a2cb87 Sep 20, 2021

Please sign in to comment.