java.util.concurrent.ExecutionException: java.io.IOException: Connection closed at java.util.concurrent.CompletableFuture.reportGet(java.base@9-internal/CompletableFuture.java:395) at java.util.concurrent.CompletableFuture.get(java.base@9-internal/CompletableFuture.java:1999)

JDK Bug System | Felix Yang | 4 months ago
  1. 0

    This can be reproduced with following WebSocket scenario. But I don't think it is only a WebSocket problem. It looks to be a problem in current java.net.http.*HttpConnection implementation //A simple test to reproduce the problem public class WSReconnectTest { public static void main(String[] args) throws Exception { String wsURL = "your_ws_endpoint"; connect(wsURL); connect(wsURL); } /** * Tests send and receive plain text messages with different length. * @throws Exception */ static void connect(String url) throws Exception { Listener l = new Listener() { @Override public void onError(WebSocket webSocket, Throwable error) { System.err.println(error); error.printStackTrace(); } }; URI uri = new URI(url); WebSocket ws= WebSocket.newBuilder(uri, l).buildAsync().get(); ws.sendClose().get(); } } It will fail immediately at the second connect attempt. Please refer to the test output:----------System.err:(24/1946)---------- java.util.concurrent.ExecutionException: java.io.IOException: Connection closed at java.util.concurrent.CompletableFuture.reportGet(java.base@9-internal/CompletableFuture.java:395) at java.util.concurrent.CompletableFuture.get(java.base@9-internal/CompletableFuture.java:1999) at WSReconnectTest.connect(WSReconnectTest.java:58) at WSReconnectTest.main(WSReconnectTest.java:42) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-internal/Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-internal/NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-internal/DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(java.base@9-internal/Method.java:535) at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:110) at java.lang.Thread.run(java.base@9-internal/Thread.java:843) Caused by: java.io.IOException: Connection closed at java.net.http.Http1Response.readHeaders(java.httpclient@9-internal/Http1Response.java:72) at java.net.http.Http1Exchange.lambda$getResponseAsyncImpl$0(java.httpclient@9-internal/Http1Exchange.java:190) at java.net.http.Utils.lambda$singleThreadExecutor$5(java.httpclient@9-internal/Utils.java:495) at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@9-internal/ThreadPoolExecutor.java:1158) at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@9-internal/ThreadPoolExecutor.java:632) at java.lang.Thread.run(java.base@9-internal/Thread.java:843) at jdk.internal.misc.InnocuousThread.run(java.base@9-internal/InnocuousThread.java:122) "java.io.IOException: Connection closed" is the cause of failing to reconnect. According java.net.http.HttpConnection.getConnectionImpl(xxx), it will try to get pooled connection if exists. But the pooled connection never got removed during closing connection. So the next attempt to connect will get the same connection which has been closed.

    JDK Bug System | 4 months ago | Felix Yang
    java.util.concurrent.ExecutionException: java.io.IOException: Connection closed at java.util.concurrent.CompletableFuture.reportGet(java.base@9-internal/CompletableFuture.java:395) at java.util.concurrent.CompletableFuture.get(java.base@9-internal/CompletableFuture.java:1999)
  2. 0

    According to the java doc " CompletableFuture<WebSocket> java.net.http.WebSocket.Builder.buildAsync() Builds a WebSocket. Returns a CompletableFuture<WebSocket> which completes normally with the WebSocket when it is connected or completes exceptionally if an error occurs. CompletableFuture may complete exceptionally with the following errors: ... • SecurityException if a security manager is set, and the caller does not have a java.net.URLPermission for the WebSocket URI ... " But, actually, it asks for following permissions: 1. java.net.URLPermission uri "GET:Sec-WebSocket-Key,Sec-WebSocket-Version" 2. java.lang.RuntimePermission "enableContextClassLoaderOverride" 3. java.net.SocketPermission "host:port" "connect,resolve" There are multiple problems here: for permission #1, is it the documented " java.net.URLPermission for the WebSocket URI "? Even yes, I suppose an example in document is needed. for permission #2, it is apparently not documented. for permission #3, not documented either. In addition, even I specified such permission, the test still fail. Please refer to the attached java file. Test output: java.util.concurrent.ExecutionException: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:45470" "connect,resolve") at java.util.concurrent.CompletableFuture.reportGet(java.base@9-internal/CompletableFuture.java:395) at java.util.concurrent.CompletableFuture.get(java.base@9-internal/CompletableFuture.java:1999) at WSPermissionTest.lambda$urlPermissionTest$6(WSPermissionTest.java:196) ... 11 more Caused by: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:45470" "connect,resolve") at java.security.AccessControlContext.checkPermission(java.base@9-internal/AccessControlContext.java:468) at java.security.AccessController.checkPermission(java.base@9-internal/AccessController.java:894) at java.lang.SecurityManager.checkPermission(java.base@9-internal/SecurityManager.java:548) at java.lang.SecurityManager.checkConnect(java.base@9-internal/SecurityManager.java:1050) at sun.nio.ch.SocketChannelImpl.connect(java.base@9-internal/SocketChannelImpl.java:627) at java.net.http.PlainHttpConnection.connect(java.httpclient@9-internal/PlainHttpConnection.java:122) at java.net.http.Http1Exchange.sendHeadersOnly(java.httpclient@9-internal/Http1Exchange.java:133) at java.net.http.ExchangeImpl.sendRequest(java.httpclient@9-internal/ExchangeImpl.java:176) at java.net.http.ExchangeImpl.lambda$sendRequestAsync$1(java.httpclient@9-internal/ExchangeImpl.java:184) at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@9-internal/ThreadPoolExecutor.java:1158) at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@9-internal/ThreadPoolExecutor.java:632) at java.lang.Thread.run(java.base@9-internal/Thread.java:843) at jdk.internal.misc.InnocuousThread.run(java.base@9-internal/InnocuousThread.java:122)

    JDK Bug System | 3 months ago | Felix Yang
    java.util.concurrent.ExecutionException: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:45470" "connect,resolve") at java.util.concurrent.CompletableFuture.reportGet(java.base@9-internal/CompletableFuture.java:395) at java.util.concurrent.CompletableFuture.get(java.base@9-internal/CompletableFuture.java:1999)
  3. 0

    The Network Adapter could not establish the connection

    apache.org | 12 months ago
    java.util.concurrent.ExecutionException: java.io.IOException: The Network Adapter could not establish the connection at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    The Network Adapter could not establish the connection

    apache.org | 1 year ago
    java.util.concurrent.ExecutionException: java.io.IOException: Already started. at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)
  6. 0

    The Network Adapter could not establish the connection

    apache.org | 12 months ago
    java.util.concurrent.ExecutionException: java.io.IOException: Already started. at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:205)

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.util.concurrent.ExecutionException

      java.io.IOException: Connection closed at java.util.concurrent.CompletableFuture.reportGet(java.base@9-internal/CompletableFuture.java:395) at java.util.concurrent.CompletableFuture.get(java.base@9-internal/CompletableFuture.java:1999)

      at WSReconnectTest.connect()
    2. Unknown
      WSReconnectTest.main
      1. WSReconnectTest.connect(WSReconnectTest.java:58)
      2. WSReconnectTest.main(WSReconnectTest.java:42)
      2 frames