Created attachment 37583 [details] patch for WsWebSocketContainer.java 8.5.37 fd leaks An attempt to create a new websocket connection with WebSocketContainer.connectToServer to an unresolvable host raises java.nio.channels.UnresolvedAddressException, but leaves some socket resources allocated. This can be verified by putting the above connect method in a loop and monitoring the open files of the java process. On linux this can be done with e.g. lsof: the number of socket fd increase on every iteration up to the OS limit, then "Too many open files" IOExceptions are raised. Browsing the org.apache.tomcat.websocket.WsWebSocketContainer.connectToServerRecursive() code I found that the call // Open the connection Future<Void> fConnect = socketChannel.connect(sa); raises the UnresolvedAddressException, leaving the socketChannel object opened. I think the same problem could arise with a proxy server that return a status code != 200, handled in lines 313-317. I tried to solve extending the try block to include the above call, changing the corresponding finally block to cover extra cases.
Thanks for the report and for the patch. The analysis looks good to me. I've applied the patch. Fixed in: - 10.0.x for 10.0.0-M11 onwards - 9.0.x for 9.0.41 onwards - 8.5.x for 8.5.61 onwards - 7.0.x for 7.0.108 onwards