You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/12/02 17:28:40 UTC
[tomcat] branch 8.5.x updated: Fix BZ-64951 - Correct potential fd
leak when WebSocket connections fail
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new a2dbd0a Fix BZ-64951 - Correct potential fd leak when WebSocket connections fail
a2dbd0a is described below
commit a2dbd0a67d42577941d3ac784f85699059563ffd
Author: Mark Thomas <ma...@apache.org>
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 b724b75..dcde690 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 e5eb7f6..2bd17f1 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -140,6 +140,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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org