diff --git a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java index bb5fd4b00d94..0750be7eeaf1 100644 --- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java +++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java @@ -255,13 +255,6 @@ private Session connectToServerRecursive(ClientEndpointHolder clientEndpointHold } ByteBuffer request = createRequest(path, reqHeaders); - AsynchronousSocketChannel socketChannel; - try { - socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup()); - } catch (IOException ioe) { - throw new DeploymentException(sm.getString("wsWebSocketContainer.asynchronousSocketChannelFail"), ioe); - } - // Get the connection timeout long timeout = Constants.IO_TIMEOUT_MS_DEFAULT; String timeoutValue = (String) userProperties.get(Constants.IO_TIMEOUT_MS_PROPERTY); @@ -269,6 +262,13 @@ private Session connectToServerRecursive(ClientEndpointHolder clientEndpointHold timeout = Long.valueOf(timeoutValue).intValue(); } + AsynchronousSocketChannel socketChannel; + try { + socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup()); + } catch (IOException ioe) { + throw new DeploymentException(sm.getString("wsWebSocketContainer.asynchronousSocketChannelFail"), ioe); + } + // Set-up // Same size as the WsFrame input buffer ByteBuffer response = ByteBuffer.allocate(getDefaultMaxBinaryMessageBufferSize());