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.
This commit is contained in:
Gary Russell
2020-04-23 17:48:52 -04:00
committed by Artem Bilan
parent 1d4626f54c
commit ca80435951
2 changed files with 12 additions and 5 deletions

View File

@@ -183,6 +183,7 @@ public abstract class AbstractClientConnectionFactory extends AbstractConnection
connection = buildNewConnection();
if (this.connectionTest != null && !this.connectionTest.test(connection)) {
connection.setTestFailed(true);
connection.close();
throw new UncheckedIOException(new IOException("Connection test failed for " + connection));
}

View File

@@ -101,6 +101,8 @@ public abstract class TcpConnectionSupport implements TcpConnection {
*/
private boolean needsTest;
private volatile boolean testFailed;
public TcpConnectionSupport() {
this(null);
}
@@ -151,6 +153,10 @@ public abstract class TcpConnectionSupport implements TcpConnection {
}
}
void setTestFailed(boolean testFailed) {
this.testFailed = testFailed;
}
/**
* Closes this connection.
*/
@@ -305,16 +311,16 @@ public abstract class TcpConnectionSupport implements TcpConnection {
*/
@Override
public TcpListener getListener() {
if (this.manualListenerRegistration) {
if (this.needsTest && this.testListener != null) {
this.needsTest = false;
return this.testListener;
}
if (this.manualListenerRegistration && !this.testFailed) {
if (this.logger.isDebugEnabled()) {
this.logger.debug(getConnectionId() + " Waiting for listener registration");
}
waitForListenerRegistration();
}
if (this.needsTest && this.testListener != null) {
this.needsTest = false;
return this.testListener;
}
return this.listener;
}