JDK-8266900 : java/net/httpclient/ShortResponseBody.java fails on windows with java.io.IOException: Unable to establish loopback connection
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: x86_64
  • Submitted: 2021-05-11
  • Updated: 2022-11-14
  • Resolved: 2022-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 b21Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Caught expected exception:java.io.IOException: HTTP/1.1 header parser received no bytes
test ShortResponseBody.testSynchronousGET("https://localhost:62310/https1/closeImmediately/foo", "no bytes", false): failure
java.io.UncheckedIOException: java.io.IOException: Unable to establish loopback connection
	at java.net.http/jdk.internal.net.http.HttpClientImpl.<init>(HttpClientImpl.java:326)
	at java.net.http/jdk.internal.net.http.HttpClientImpl.create(HttpClientImpl.java:268)
	at java.net.http/jdk.internal.net.http.HttpClientBuilderImpl.build(HttpClientBuilderImpl.java:135)
	at ShortResponseBody.newHttpClient(ShortResponseBody.java:224)
	at ShortResponseBody.testSynchronousGET(ShortResponseBody.java:235)
	at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
	at org.testng.TestRunner.privateRun(TestRunner.java:773)
	at org.testng.TestRunner.run(TestRunner.java:623)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
	at org.testng.SuiteRunner.run(SuiteRunner.java:259)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
	at org.testng.TestNG.run(TestNG.java:1018)
	at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:94)
	at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:54)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
	at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.io.IOException: Unable to establish loopback connection
	at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:101)
	at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:67)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
	at java.base/sun.nio.ch.PipeImpl.<init>(PipeImpl.java:194)
	at java.base/sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:142)
	at java.base/sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:44)
	at java.base/java.nio.channels.Selector.open(Selector.java:295)
	at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.<init>(HttpClientImpl.java:717)
	at java.net.http/jdk.internal.net.http.HttpClientImpl.<init>(HttpClientImpl.java:323)
	... 32 more
Caused by: java.net.BindException: Address already in use: connect
	at java.base/sun.nio.ch.Net.connect0(Native Method)
	at java.base/sun.nio.ch.Net.connect(Net.java:576)
	at java.base/sun.nio.ch.Net.connect(Net.java:583)
	at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:851)
	at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:285)
	at java.base/sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(PipeImpl.java:131)
	at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:83)
	... 40 more

Comments
Changeset: 329b49a9 Author: Daniel JeliƄski <djelinski@openjdk.org> Date: 2022-10-24 06:07:10 +0000 URL: https://git.openjdk.org/jdk/commit/329b49a938a125908f0eff403dfc38a04aec96a1
24-10-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10794 Date: 2022-10-20 12:58:13 +0000
20-10-2022

The test failed because the OS run out of ephemeral ports. The OS has a limited number of ephemeral ports at its disposal. After use, the ports are blocked in TIME_WAIT state for a system-dependent period of time (between 30 seconds and 4 minutes). There are 3 ShortResponseBody tests, and each one sends 570 requests; each request uses at least one ephemeral port - may use two ports if the request is retried internally. Additionally on Windows 2016 and older, each http client uses a TCP socket (2 ports) for selector; on newer Windows versions a Unix domain socket is used, which does not consume ephemeral ports. Looking at the tests, they repeat the same requests over and over again; I believe we could reduce the number of requests performed without impacting code coverage.
20-10-2022

The observed exception occurs on platform where Unix Domain Sockets are not available. See JDK-8280944.
13-10-2022

Maybe the test should be instrumented to pause and gives some time for the GC to garbage collect released HttpClient instances when that exception happens.
11-05-2021