@@ -992,12 +992,10 @@ private PooledConnection acquirePermitOrGetAvailableOpenedConnection(final boole
992
992
expressedDesireToGetAvailableConnection = true ;
993
993
}
994
994
long remainingNanos = timeout .remainingOrInfinite (NANOSECONDS );
995
- while (permits == 0 ) {
996
- stateAndGeneration .throwIfClosedOrPaused ();
997
- availableConnection = tryGetAvailable ? tryGetAvailableConnection () : null ;
998
- if (availableConnection != null ) {
999
- break ;
1000
- }
995
+ while (permits == 0
996
+ // the absence of short-circuiting is of importance
997
+ & !stateAndGeneration .throwIfClosedOrPaused ()
998
+ & (availableConnection = tryGetAvailable ? tryGetAvailableConnection () : null ) == null ) {
1001
999
if (Timeout .expired (remainingNanos )) {
1002
1000
throw createTimeoutException (timeout );
1003
1001
}
@@ -1523,11 +1521,14 @@ boolean close() {
1523
1521
}
1524
1522
1525
1523
/**
1524
+ * @return {@code false} which means that the method did not throw.
1525
+ * The method returns to allow using it conveniently as part of a condition check when waiting on a {@link Condition}.
1526
+ * Short-circuiting operators {@code &&} and {@code ||} must not be used with this method to ensure that it is called.
1526
1527
* @throws MongoServerUnavailableException If and only if {@linkplain #close() closed}.
1527
1528
* @throws MongoConnectionPoolClearedException If and only if {@linkplain #pauseAndIncrementGeneration(Throwable) paused}
1528
1529
* and not {@linkplain #close() closed}.
1529
1530
*/
1530
- void throwIfClosedOrPaused () {
1531
+ boolean throwIfClosedOrPaused () {
1531
1532
if (closed .get ()) {
1532
1533
throw pool .poolClosedException ();
1533
1534
}
@@ -1541,6 +1542,7 @@ void throwIfClosedOrPaused() {
1541
1542
lock .readLock ().unlock ();
1542
1543
}
1543
1544
}
1545
+ return false ;
1544
1546
}
1545
1547
}
1546
1548
}
0 commit comments