This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 9da6126 Fix BZ-64951 - Correct potential fd leak when WebSocket
connections fail
9da6126 is described below
commit 9da6126e84099974de3e109e4f0eba68314b24c2
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Dec 2 17:27:21 2020 +0000
Fix BZ-64951 - Correct potential fd leak when WebSocket connections fail
https://bz.apache.org/bugzilla/show_bug.cgi?id=64951
Patch provided by Maurizio Adami
---
.../tomcat/websocket/WsWebSocketContainer.java | 51 +++++++++++-----------
webapps/docs/changelog.xml | 9 ++++
2 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
index 0db496f..4bc8f6a 100644
--- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
+++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
@@ -304,13 +304,13 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
boolean success = false;
List<Extension> extensionsAgreed = new ArrayList<>();
Transformation transformation = null;
-
- // Open the connection
- Future<Void> fConnect = socketChannel.connect(sa);
AsyncChannelWrapper channel = null;
- if (proxyConnect != null) {
- try {
+ try {
+ // Open the connection
+ Future<Void> fConnect = socketChannel.connect(sa);
+
+ if (proxyConnect != null) {
fConnect.get(timeout, TimeUnit.MILLISECONDS);
// Proxy CONNECT is clear text
channel = new AsyncChannelWrapperNonSecure(socketChannel);
@@ -321,29 +321,20 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
"wsWebSocketContainer.proxyConnectFail",
selectedProxy,
Integer.toString(httpResponse.getStatus())));
}
- } catch (TimeoutException | InterruptedException |
ExecutionException |
- EOFException e) {
- if (channel != null) {
- channel.close();
- }
- throw new DeploymentException(
-
sm.getString("wsWebSocketContainer.httpRequestFailed"), e);
}
- }
- 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);
+ }
- try {
fConnect.get(timeout, TimeUnit.MILLISECONDS);
Future<Void> fHandshake = channel.handshake();
@@ -499,7 +490,15 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
throw new
DeploymentException(sm.getString("wsWebSocketContainer.httpRequestFailed",
path), e);
} finally {
if (!success) {
- channel.close();
+ if (channel != null) {
+ channel.close();
+ } else {
+ try {
+ socketChannel.close();
+ } catch (IOException ioe) {
+ // Ignore
+ }
+ }
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 4f3821a..0f2d87b 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -147,6 +147,15 @@
</fix>
</changelog>
</subsection>
+ <subsection name="WebSocket">
+ <changelog>
+ <fix>
+ <bug>64951</bug>: Fix a potential file descriptor leak when WebSocket
+ connections are attempted and fail. Patch provided by Maurizio Adami.
+ (markt)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Web applications">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]