GH-8785: Propagate WebSocket client connect fail

Fixes https://github.com/spring-projects/spring-integration/issues/8785

The `ClientWebSocketContainer.start()` delegates to the `IntegrationWebSocketConnectionManager`
which performs an async connection to the server.

* Wait for `connectionLatch` in the `ClientWebSocketContainer.start()`
and check for `this.openConnectionException != null` to re-throw.
Mark `ClientWebSocketContainer` as stopped in that case

**Cherry-pick to `6.1.x` & `6.0.x`**
This commit is contained in:
Artem Bilan
2023-11-03 11:57:01 -04:00
committed by Christian Tzolov
parent bcfd81abba
commit 537add5cf0
2 changed files with 30 additions and 3 deletions

View File

@@ -192,6 +192,20 @@ public final class ClientWebSocketContainer extends IntegrationWebSocketContaine
this.openConnectionException = null;
this.connectionLatch = new CountDownLatch(1);
this.connectionManager.start();
try {
this.connectionLatch.await(this.connectionTimeout, TimeUnit.SECONDS);
}
catch (InterruptedException ex) {
logger.error("'clientSession' has not been established during 'openConnection'");
}
if (this.openConnectionException != null) {
// The next 'this.connectionManager.stop()' call resets 'this.openConnectionException' to null
IllegalStateException exceptionToRethrow = new IllegalStateException(this.openConnectionException);
this.connectionManager.stop();
throw exceptionToRethrow;
}
}
}
finally {