Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8308336: Test java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java failed: java.net.BindException: Address already in use #14177

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -27,8 +27,11 @@
* @summary Verify that expect 100-continue doesn't hang
* @library /test/lib
* @run junit/othervm HttpURLConnectionExpectContinueTest
* @run junit/othervm -Djava.net.preferIPv4Stack=True HttpURLConnectionExpectContinueTest
* @run junit/othervm -Djava.net.preferIPv6Addresses=True HttpURLConnectionExpectContinueTest
*/

import jdk.test.lib.net.URIBuilder;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -73,7 +76,7 @@ public void startServerSocket() throws Exception {

control.serverSocket = new ServerSocket();
control.serverSocket.setReuseAddress(true);
control.serverSocket.bind(new InetSocketAddress("127.0.0.1", 0));
control.serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
Runnable runnable = () -> {
while (!control.stop) {
try {
@@ -419,8 +422,12 @@ public void testFixedLengthRequestWithDoubleExpect100ContinueResponse() throws E
}

// Creates a connection with all the common settings used in each test
private HttpURLConnection createConnection() throws IOException {
URL url = new URL("http://localhost:" + control.serverSocket.getLocalPort());
private HttpURLConnection createConnection() throws Exception {
URL url = URIBuilder.newBuilder()
.scheme("http")
.host(InetAddress.getLoopbackAddress())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change the call flow of the test in a slightly subtle way. In the original the "host" is supplied i.e. localhost which should map to the loopback address, and in the change the loopback IP address is being supplied diectly. In terms of equivalence then supplying a host string might be more appropriate:
.host("localhost")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that's precisely what we want to avoid. Because how "localhost" maps to an InetAddress depends on the machine configuration, which is a recipe for intermittent failures.

I'd suggest:

        URL url = URIBuilder.newBuilder()
                .scheme("http")
                .localhost()

(which is actually the same)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a glance there isn't a .localhost() only a .loopback() is that what you were referring to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Sorry - my mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed that change now and am currently rerunning tests

.port(control.serverSocket.getLocalPort())
.toURL();

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);