Skip to content

Commit ca80435

Browse files
garyrussellartembilan
authored andcommitted
GH-3256: Fix interaction with delayed listener reg
- Use the test listener before waiting for delayed listener registration. - Don't wait for delayed listener registration if the test fails.
1 parent 1d4626f commit ca80435

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractClientConnectionFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ private TcpConnectionSupport doObtain(boolean singleUse) {
183183

184184
connection = buildNewConnection();
185185
if (this.connectionTest != null && !this.connectionTest.test(connection)) {
186+
connection.setTestFailed(true);
186187
connection.close();
187188
throw new UncheckedIOException(new IOException("Connection test failed for " + connection));
188189
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public abstract class TcpConnectionSupport implements TcpConnection {
101101
*/
102102
private boolean needsTest;
103103

104+
private volatile boolean testFailed;
105+
104106
public TcpConnectionSupport() {
105107
this(null);
106108
}
@@ -151,6 +153,10 @@ public TcpConnectionSupport(Socket socket, boolean server, boolean lookupHost,
151153
}
152154
}
153155

156+
void setTestFailed(boolean testFailed) {
157+
this.testFailed = testFailed;
158+
}
159+
154160
/**
155161
* Closes this connection.
156162
*/
@@ -305,16 +311,16 @@ public void registerSender(@Nullable TcpSender sender) {
305311
*/
306312
@Override
307313
public TcpListener getListener() {
308-
if (this.manualListenerRegistration) {
314+
if (this.needsTest && this.testListener != null) {
315+
this.needsTest = false;
316+
return this.testListener;
317+
}
318+
if (this.manualListenerRegistration && !this.testFailed) {
309319
if (this.logger.isDebugEnabled()) {
310320
this.logger.debug(getConnectionId() + " Waiting for listener registration");
311321
}
312322
waitForListenerRegistration();
313323
}
314-
if (this.needsTest && this.testListener != null) {
315-
this.needsTest = false;
316-
return this.testListener;
317-
}
318324
return this.listener;
319325
}
320326

0 commit comments

Comments
 (0)