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

alexpl 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 7f35ec7e96e IGNITE-22862 Add address information to 
ClientConnectionException stacktrace - Fixes #11462.
7f35ec7e96e is described below

commit 7f35ec7e96ea420c447cda1731fe11782298abd8
Author: Maksim Davydov <[email protected]>
AuthorDate: Tue Aug 13 09:39:16 2024 +0300

    IGNITE-22862 Add address information to ClientConnectionException 
stacktrace - Fixes #11462.
    
    Signed-off-by: Aleksey Plekhanov <[email protected]>
---
 .../ignite/common/NodeSslConnectionMetricTest.java | 24 +++++++++++++++-------
 .../internal/client/thin/ReliableChannel.java      |  7 ++++---
 .../internal/client/thin/TcpClientChannel.java     | 17 ++++++++-------
 .../GridNioClientConnectionMultiplexer.java        |  2 +-
 .../org/apache/ignite/client/ReliabilityTest.java  | 10 +++++++--
 .../internal/client/thin/FunctionalTest.java       |  3 +++
 6 files changed, 43 insertions(+), 20 deletions(-)

diff --git 
a/modules/clients/src/test/java/org/apache/ignite/common/NodeSslConnectionMetricTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/common/NodeSslConnectionMetricTest.java
index 833d324ea9a..f34c2437243 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/common/NodeSslConnectionMetricTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/common/NodeSslConnectionMetricTest.java
@@ -59,6 +59,7 @@ import static 
org.apache.ignite.internal.util.nio.GridNioServer.SSL_ENABLED_METR
 import static 
org.apache.ignite.internal.util.nio.ssl.GridNioSslFilter.SSL_HANDSHAKE_DURATION_HISTOGRAM_METRIC_NAME;
 import static 
org.apache.ignite.internal.util.nio.ssl.GridNioSslFilter.SSL_REJECTED_SESSIONS_CNT_METRIC_NAME;
 import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.COMMUNICATION_METRICS_GROUP_NAME;
+import static org.apache.ignite.testframework.GridTestUtils.assertContains;
 import static 
org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause;
 import static org.apache.ignite.testframework.GridTestUtils.keyStorePassword;
 import static org.apache.ignite.testframework.GridTestUtils.keyStorePath;
@@ -73,6 +74,9 @@ public class NodeSslConnectionMetricTest extends 
GridCommonAbstractTest {
     /** Cipher suite not supported by cluster nodes. */
     private static final String UNSUPPORTED_CIPHER_SUITE = 
"TLS_RSA_WITH_AES_128_GCM_SHA256";
 
+    /** Local server address. */
+    private static final String LOCAL_CLIENT_ADDRESS = "127.0.0.1:10800";
+
     /** Metric timeout. */
     private static final long TIMEOUT = 7_000;
 
@@ -295,26 +299,32 @@ public class NodeSslConnectionMetricTest extends 
GridCommonAbstractTest {
         checkSslCommunicationMetrics(reg, 1, 0, 0);
 
         // Tests untrusted certificate.
-        assertThrowsWithCause(() ->
-            startClient(clientConfiguration("client", "trustboth", 
CIPHER_SUITE, "TLSv1.2")),
+        Throwable ex = assertThrowsWithCause(() ->
+                startClient(clientConfiguration("client", "trustboth", 
CIPHER_SUITE, "TLSv1.2")),
             ClientConnectionException.class);
 
+        assertContains(log, ex.getMessage(), LOCAL_CLIENT_ADDRESS);
+
         checkSslCommunicationMetrics(reg, 2, 0, 1);
 
         // Tests unsupported cipher suites.
-        assertThrowsWithCause(() ->
-            startClient(clientConfiguration("thinClient", "trusttwo", 
UNSUPPORTED_CIPHER_SUITE, "TLSv1.2")),
+        ex = assertThrowsWithCause(() ->
+                startClient(clientConfiguration("thinClient", "trusttwo", 
UNSUPPORTED_CIPHER_SUITE, "TLSv1.2")),
             ClientConnectionException.class
         );
 
+        assertContains(log, ex.getMessage(), LOCAL_CLIENT_ADDRESS);
+
         checkSslCommunicationMetrics(reg, 3, 0, 2);
 
         // Tests mismatched protocol versions.
-        assertThrowsWithCause(() ->
-            startClient(clientConfiguration("thinClient", "trusttwo", null, 
"TLSv1.1")),
+        ex = assertThrowsWithCause(() ->
+                startClient(clientConfiguration("thinClient", "trusttwo", 
null, "TLSv1.1")),
             ClientConnectionException.class
         );
 
+        assertContains(log, ex.getMessage(), LOCAL_CLIENT_ADDRESS);
+
         checkSslCommunicationMetrics(reg, 4, 0, 3);
     }
 
@@ -389,7 +399,7 @@ public class NodeSslConnectionMetricTest extends 
GridCommonAbstractTest {
         String protocol
     ) {
         return new ClientConfiguration()
-            .setAddresses("127.0.0.1:10800")
+            .setAddresses(LOCAL_CLIENT_ADDRESS)
             // When PA is enabled, async client channel init executes and 
spoils the metrics.
             .setPartitionAwarenessEnabled(false)
             .setSslMode(SslMode.REQUIRED)
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
index f3ae29c0e1d..6559ea8f739 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
@@ -1039,18 +1039,19 @@ final class ReliableChannel implements AutoCloseable {
         private ClientChannel getOrCreateChannel(boolean ignoreThrottling)
             throws ClientConnectionException, ClientAuthenticationException, 
ClientProtocolError {
             if (close)
-                throw new ClientConnectionException("Channel is closed");
+                throw new ClientConnectionException("Channel is closed 
[addresses=" + getAddresses() + ']');
 
             if (ch == null) {
                 synchronized (this) {
                     if (close)
-                        throw new ClientConnectionException("Channel is 
closed");
+                        throw new ClientConnectionException("Channel is closed 
[addresses=" + getAddresses() + ']');
 
                     if (ch != null)
                         return ch;
 
                     if (!ignoreThrottling && applyReconnectionThrottling())
-                        throw new ClientConnectionException("Reconnect is not 
allowed due to applied throttling");
+                        throw new ClientConnectionException("Reconnect is not 
allowed due to applied throttling" +
+                            " [addresses=" + getAddresses() + ']');
 
                     ClientChannel channel = chFactory.apply(chCfg, connMgr);
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
index b6ec35f9c56..f0eee5cbb5c 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
@@ -73,6 +73,7 @@ import 
org.apache.ignite.internal.processors.platform.client.ClientStatus;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.logger.NullLogger;
 import org.jetbrains.annotations.Nullable;
@@ -280,7 +281,8 @@ class TcpClientChannel implements ClientChannel, 
ClientMessageHandler, ClientCon
 
             try {
                 for (ClientRequestFuture pendingReq : pendingReqs.values())
-                    pendingReq.onDone(new ClientConnectionException("Channel 
is closed", cause));
+                    pendingReq.onDone(new ClientConnectionException("Channel 
is closed [remoteAddress="
+                        + sock.remoteAddress() + ']', cause));
             }
             finally {
                 pendingReqsLock.writeLock().unlock();
@@ -349,7 +351,8 @@ class TcpClientChannel implements ClientChannel, 
ClientMessageHandler, ClientCon
 
             try {
                 if (closed()) {
-                    ClientConnectionException err = new 
ClientConnectionException("Channel is closed");
+                    ClientConnectionException err = new 
ClientConnectionException("Channel is closed [remoteAddress="
+                        + sock.remoteAddress() + ']');
 
                     eventListener.onRequestFail(connDesc, id, op.code(), 
op.name(), System.nanoTime() - startTimeNanos, err);
 
@@ -631,7 +634,7 @@ class TcpClientChannel implements ClientChannel, 
ClientMessageHandler, ClientCon
 
         try {
             if (closed())
-                throw new ClientConnectionException("Channel is closed");
+                throw new ClientConnectionException("Channel is closed 
[remoteAddress=" + sock.remoteAddress() + ']');
 
             Map<Long, NotificationListener> lsnrs = 
notificationLsnrs[type.ordinal()];
 
@@ -710,7 +713,7 @@ class TcpClientChannel implements ClientChannel, 
ClientMessageHandler, ClientCon
 
             try {
                 if (closed())
-                    throw new ClientConnectionException("Channel is closed");
+                    throw new ClientConnectionException("Channel is closed 
[remoteAddress=" + sock.remoteAddress() + ']');
 
                 fut = new ClientRequestFuture(reqId, 
ClientOperation.HANDSHAKE);
 
@@ -807,7 +810,7 @@ class TcpClientChannel implements ClientChannel, 
ClientMessageHandler, ClientCon
                 if (e instanceof IOException)
                     err = handleIOError((IOException)e);
                 else
-                    err = new ClientConnectionException(e.getMessage(), e);
+                    err = new ClientConnectionException(e.getMessage() + " 
[remoteAddress=" + sock.remoteAddress() + ']', e);
 
                 eventListener.onHandshakeFail(
                     new ConnectionDescription(sock.localAddress(), 
sock.remoteAddress(), new ProtocolContext(ver).toString(), null),
@@ -879,7 +882,7 @@ class TcpClientChannel implements ClientChannel, 
ClientMessageHandler, ClientCon
             lastSendMillis = System.currentTimeMillis();
         }
         catch (IgniteCheckedException e) {
-            throw new ClientConnectionException(e.getMessage(), e);
+            throw new ClientConnectionException(e.getMessage() + " 
[remoteAddress=" + sock.remoteAddress() + ']', e);
         }
     }
 
@@ -887,7 +890,7 @@ class TcpClientChannel implements ClientChannel, 
ClientMessageHandler, ClientCon
      * @param ex IO exception (cause).
      */
     private ClientException handleIOError(@Nullable IOException ex) {
-        return handleIOError("sock=" + sock, ex);
+        return handleIOError(S.toString(ConnectionDescription.class, 
connDesc), ex);
     }
 
     /**
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 e81c2718bac..2e4cb0d25e0 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
@@ -194,7 +194,7 @@ public class GridNioClientConnectionMultiplexer implements 
ClientConnectionMulti
             return new GridNioClientConnection(ses, msgHnd, stateHnd);
         }
         catch (Exception e) {
-            throw new ClientConnectionException(e.getMessage(), e);
+            throw new ClientConnectionException(e.getMessage() + " 
[remoteAddress=" + addr + ']', e);
         }
         finally {
             rwLock.readLock().unlock();
diff --git 
a/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java 
b/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java
index 4af6805f1e4..81127e8d091 100644
--- a/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java
@@ -205,7 +205,9 @@ public class ReliabilityTest extends AbstractThinClientTest 
{
             // Fail.
             dropAllThinClientConnections(Ignition.allGrids().get(0));
 
-            GridTestUtils.assertThrowsWithCause(() -> cachePut(cache, 0, 0), 
ClientConnectionException.class);
+            Throwable ex = GridTestUtils.assertThrowsWithCause(() -> 
cachePut(cache, 0, 0), ClientConnectionException.class);
+
+            GridTestUtils.assertContains(null, ex.getMessage(), 
F.first(cluster.clientAddresses()));
 
             // Recover after fail.
             cachePut(cache, 0, 0);
@@ -278,10 +280,14 @@ public class ReliabilityTest extends 
AbstractThinClientTest {
             Throwable asyncEx = GridTestUtils.assertThrows(null, () -> 
cache.getAsync(0).get(),
                     ExecutionException.class, "Channel is closed");
 
+            GridTestUtils.assertContains(null, asyncEx.getMessage(), 
F.first(cluster.clientAddresses()));
+
             dropAllThinClientConnections(Ignition.allGrids().get(0));
 
             Throwable syncEx = GridTestUtils.assertThrows(null, () -> 
cache.get(0),
-                    ClientConnectionException.class, "Channel is closed");
+                ClientConnectionException.class, "Channel is closed");
+
+            GridTestUtils.assertContains(null, syncEx.getMessage(), 
F.first(cluster.clientAddresses()));
 
             for (Throwable t : new Throwable[] {asyncEx.getCause(), syncEx}) {
                 assertEquals("Error in policy.", 
t.getSuppressed()[0].getMessage());
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
index c278fc5f3d8..61125b0bd5c 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/FunctionalTest.java
@@ -95,6 +95,7 @@ import static 
org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbs
 import static 
org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL2;
 import static 
org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL3;
 import static 
org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST;
+import static org.apache.ignite.testframework.GridTestUtils.assertContains;
 import static 
org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause;
 import static org.apache.ignite.testframework.GridTestUtils.runAsync;
 import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
@@ -644,6 +645,8 @@ public class FunctionalTest extends 
AbstractBinaryArraysTest {
             String.format("%s expected but no exception was received", 
ClientConnectionException.class.getName()),
             expEx
         );
+
+        assertContains(log, expEx.getMessage(), Config.SERVER);
     }
 
 

Reply via email to