This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new eb57f7d7714 IGNITE-20740 Fix SocketChannel leak when connection fails 
(#11016)
eb57f7d7714 is described below

commit eb57f7d771430c5f3bd8e10c1c4de77b4314d8fe
Author: ZhangJian He <[email protected]>
AuthorDate: Tue Oct 31 03:35:58 2023 +0800

    IGNITE-20740 Fix SocketChannel leak when connection fails (#11016)
    
    Co-authored-by: Pavel Tupitsyn <[email protected]>
---
 .../GridNioClientConnectionMultiplexer.java        | 27 ++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/io/gridnioserver/GridNioClientConnectionMultiplexer.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/io/gridnioserver/GridNioClientConnectionMultiplexer.java
index 8951e0f4bcc..e81c2718bac 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/io/gridnioserver/GridNioClientConnectionMultiplexer.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/io/gridnioserver/GridNioClientConnectionMultiplexer.java
@@ -146,8 +146,31 @@ public class GridNioClientConnectionMultiplexer implements 
ClientConnectionMulti
         rwLock.readLock().lock();
 
         try {
-            SocketChannel ch = SocketChannel.open();
-            ch.socket().connect(new InetSocketAddress(addr.getHostName(), 
addr.getPort()), connTimeout);
+            SocketChannel ch = null;
+            try {
+                ch = SocketChannel.open();
+                ch.socket().connect(new InetSocketAddress(addr.getHostName(), 
addr.getPort()), connTimeout);
+            }
+            catch (Exception e) {
+                if (ch != null) {
+                    if (ch.socket() != null) {
+                        try {
+                            ch.socket().close();
+                        }
+                        catch (Exception ignored) {
+                            // ignore close exception
+                        }
+                    }
+
+                    try {
+                        ch.close();
+                    }
+                    catch (Exception ignored) {
+                        // ignore close exception
+                    }
+                }
+                throw new ClientConnectionException(e.getMessage(), e);
+            }
 
             Map<Integer, Object> meta = new HashMap<>();
             GridNioFuture<?> sslHandshakeFut = null;

Reply via email to