Skip to content

Commit 3f205f3

Browse files
authored
fix: verify connection is not a stale writer in the monitor (#1322)
1 parent adec50d commit 3f205f3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,18 @@ public void run() {
868868
connection = null;
869869
}
870870

871+
if (!StringUtils.isNullOrEmpty(writerId)) {
872+
try {
873+
if (this.servicesContainer.getPluginService().getHostRole(connection) != HostRole.WRITER) {
874+
// The first connection after failover may be stale.
875+
writerId = null;
876+
}
877+
} catch (SQLException e) {
878+
// Invalid connection, retry.
879+
continue;
880+
}
881+
}
882+
871883
if (!StringUtils.isNullOrEmpty(writerId)) {
872884
// this prevents closing connection in finally block
873885
if (!this.monitor.nodeThreadsWriterConnection.compareAndSet(null, connection)) {

0 commit comments

Comments
 (0)