You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2022/06/28 16:31:21 UTC

[ignite] branch master updated: IGNITE-17247 Fix race condition on close in GridNioClientConnectionMultiplexer (#10115)

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 fb778a084ad IGNITE-17247 Fix race condition on close in GridNioClientConnectionMultiplexer (#10115)
fb778a084ad is described below

commit fb778a084ad3c913cb87d517e25fa36130fc658c
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Tue Jun 28 19:31:13 2022 +0300

    IGNITE-17247 Fix race condition on close in GridNioClientConnectionMultiplexer (#10115)
    
    When `GridNioServer.createSession` is called concurrently with `GridNioServer.stop`, it is possible that `GridNioFuture` returned by `createSession` will never complete. Add RW lock in `GridNioClientConnectionMultiplexer` to fix this.
---
 .../GridNioClientConnectionMultiplexer.java        | 30 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 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 4a041f99afb..dab8d1a60bd 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
@@ -23,6 +23,8 @@ import java.nio.ByteOrder;
 import java.nio.channels.SocketChannel;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.net.ssl.SSLContext;
 
 import org.apache.ignite.IgniteCheckedException;
@@ -60,6 +62,9 @@ public class GridNioClientConnectionMultiplexer implements ClientConnectionMulti
     /** */
     private final SSLContext sslCtx;
 
+    /** */
+    private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+
     /**
      * Constructor.
      *
@@ -107,12 +112,26 @@ public class GridNioClientConnectionMultiplexer implements ClientConnectionMulti
 
     /** {@inheritDoc} */
     @Override public void start() {
-        srv.start();
+        rwLock.writeLock().lock();
+
+        try {
+            srv.start();
+        }
+        finally {
+            rwLock.writeLock().unlock();
+        }
     }
 
     /** {@inheritDoc} */
-    @Override public void stop() {
-        srv.stop();
+    @Override public synchronized void stop() {
+        rwLock.writeLock().lock();
+
+        try {
+            srv.stop();
+        }
+        finally {
+            rwLock.writeLock().unlock();
+        }
     }
 
     /** {@inheritDoc} */
@@ -120,6 +139,8 @@ public class GridNioClientConnectionMultiplexer implements ClientConnectionMulti
                                            ClientMessageHandler msgHnd,
                                            ClientConnectionStateHandler stateHnd)
             throws ClientConnectionException {
+        rwLock.readLock().lock();
+
         try {
             SocketChannel ch = SocketChannel.open();
             ch.socket().connect(new InetSocketAddress(addr.getHostName(), addr.getPort()), Integer.MAX_VALUE);
@@ -143,5 +164,8 @@ public class GridNioClientConnectionMultiplexer implements ClientConnectionMulti
         catch (Exception e) {
             throw new ClientConnectionException(e.getMessage(), e);
         }
+        finally {
+            rwLock.readLock().unlock();
+        }
     }
 }