@@ -992,12 +992,10 @@ private PooledConnection acquirePermitOrGetAvailableOpenedConnection(final boole
992992 expressedDesireToGetAvailableConnection = true ;
993993 }
994994 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 ) {
1001999 if (Timeout .expired (remainingNanos )) {
10021000 throw createTimeoutException (timeout );
10031001 }
@@ -1523,11 +1521,14 @@ boolean close() {
15231521 }
15241522
15251523 /**
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.
15261527 * @throws MongoServerUnavailableException If and only if {@linkplain #close() closed}.
15271528 * @throws MongoConnectionPoolClearedException If and only if {@linkplain #pauseAndIncrementGeneration(Throwable) paused}
15281529 * and not {@linkplain #close() closed}.
15291530 */
1530- void throwIfClosedOrPaused () {
1531+ boolean throwIfClosedOrPaused () {
15311532 if (closed .get ()) {
15321533 throw pool .poolClosedException ();
15331534 }
@@ -1541,6 +1542,7 @@ void throwIfClosedOrPaused() {
15411542 lock .readLock ().unlock ();
15421543 }
15431544 }
1545+ return false ;
15441546 }
15451547 }
15461548}
0 commit comments