diff -r a/WsWebSocketContainer.java b/WsWebSocketContainer.java 302,303d301 < // Open the connection < Future fConnect = socketChannel.connect(sa); 305,307c303,307 < < if (proxyConnect != null) { < try { --- > try { > // Open the connection > Future fConnect = socketChannel.connect(sa); > > if (proxyConnect != null) { 318,324d317 < } catch (TimeoutException | InterruptedException | ExecutionException | < EOFException e) { < if (channel != null) { < channel.close(); < } < throw new DeploymentException( < sm.getString("wsWebSocketContainer.httpRequestFailed"), e); 326d318 < } 328,338c320,330 < if (secure) { < // Regardless of whether a non-secure wrapper was created for a < // proxy CONNECT, need to use TLS from this point on so wrap the < // original AsynchronousSocketChannel < SSLEngine sslEngine = createSSLEngine(userProperties, host, port); < channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); < } else if (channel == null) { < // Only need to wrap as this point if it wasn't wrapped to process a < // proxy CONNECT < channel = new AsyncChannelWrapperNonSecure(socketChannel); < } --- > if (secure) { > // Regardless of whether a non-secure wrapper was created for a > // proxy CONNECT, need to use TLS from this point on so wrap the > // original AsynchronousSocketChannel > SSLEngine sslEngine = createSSLEngine(userProperties, host, port); > channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); > } else if (channel == null) { > // Only need to wrap as this point if it wasn't wrapped to process a > // proxy CONNECT > channel = new AsyncChannelWrapperNonSecure(socketChannel); > } 340d331 < try { 489c480,487 < channel.close(); --- > if (channel != null) { > channel.close(); > } > else { > try { > socketChannel.close(); > } catch (Exception ignore) { } > } 1124d1121 <