@@ -899,6 +899,7 @@ protected Node curNode() {
899899 * @param now The current time in milliseconds.
900900 * @param throwable The failure exception.
901901 */
902+ @ SuppressWarnings ("NPathComplexity" )
902903 final void fail (long now , Throwable throwable ) {
903904 if (curNode != null ) {
904905 runnable .nodeReadyDeadlines .remove (curNode );
@@ -920,6 +921,11 @@ final void fail(long now, Throwable throwable) {
920921 }
921922 nextAllowedTryMs = now + retryBackoff .backoff (tries ++);
922923
924+ // Don't mask OutOfMemoryError as TimeoutException - propagate it directly
925+ if (throwable instanceof OutOfMemoryError ) {
926+ handleFailure (throwable );
927+ return ;
928+ }
923929 // If the call has timed out, fail.
924930 if (calcTimeoutMsRemainingAsInt (now , deadlineMs ) <= 0 ) {
925931 handleTimeoutFailure (now , throwable );
@@ -955,10 +961,7 @@ private void handleTimeoutFailure(long now, Throwable cause) {
955961 log .debug ("{} timed out at {} after {} attempt(s)" , this , now , tries ,
956962 new Exception (prettyPrintException (cause )));
957963 }
958- // Don't mask OutOfMemoryError as TimeoutException - propagate it directly
959- if (cause instanceof OutOfMemoryError ) {
960- handleFailure (cause );
961- } else if (cause instanceof TimeoutException ) {
964+ if (cause instanceof TimeoutException ) {
962965 handleFailure (cause );
963966 } else {
964967 handleFailure (new TimeoutException (this + " timed out at " + now
0 commit comments