Skip to content

Commit cb09650

Browse files
authored
fix: isValidTimeout potentially rounded down to 0 (#1546)
1 parent a55f1fe commit cb09650

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

wrapper/src/main/java/software/amazon/jdbc/plugin/efm2/HostMonitorImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class HostMonitorImpl extends AbstractMonitor implements HostMonitor {
5252
private static final long THREAD_SLEEP_NANO = TimeUnit.MILLISECONDS.toNanos(100);
5353
private static final long TERMINATION_TIMEOUT_SEC = 30;
5454
private static final String MONITORING_PROPERTY_PREFIX = "monitoring-";
55+
private static final int MIN_VALIDITY_CHECK_TIMEOUT_SEC = 1;
5556

5657
protected static final Executor ABORT_EXECUTOR =
5758
ExecutorFactory.newSingleThreadExecutor("abort");
@@ -323,7 +324,8 @@ boolean checkConnectionStatus() {
323324
// Some drivers, like MySQL Connector/J, execute isValid() in a double of specified timeout time.
324325
final int validTimeout = (int) TimeUnit.NANOSECONDS.toSeconds(
325326
this.failureDetectionIntervalNano - THREAD_SLEEP_NANO) / 2;
326-
return this.monitoringConn.isValid(validTimeout);
327+
// validTimeout could get rounded down to 0.
328+
return this.monitoringConn.isValid(Math.max(MIN_VALIDITY_CHECK_TIMEOUT_SEC, validTimeout));
327329
} catch (final SQLException sqlEx) {
328330
return false;
329331
} finally {

0 commit comments

Comments
 (0)