@@ -324,21 +324,6 @@ async function executeOperationWithRetries<
324324 throw error ;
325325 }
326326
327- if ( operationError . hasErrorLabel ( MongoErrorLabel . SystemOverloadedError ) ) {
328- const backoffMS = Math . random ( ) * Math . min ( MAX_BACKOFF_MS , BASE_BACKOFF_MS * 2 ** attempt ) ;
329-
330- // if the backoff would exhaust the CSOT timeout, short-circuit.
331- if ( timeoutContext . csotEnabled ( ) && backoffMS > timeoutContext . remainingTimeMS ) {
332- throw error ;
333- }
334-
335- if ( topology . s . options . adaptiveRetries && ! topology . tokenBucket . consume ( RETRY_COST ) ) {
336- throw error ;
337- }
338-
339- await setTimeout ( backoffMS ) ;
340- }
341-
342327 if (
343328 operationError instanceof MongoNetworkError &&
344329 operation . hasAspect ( Aspect . CURSOR_CREATING ) &&
@@ -351,13 +336,29 @@ async function executeOperationWithRetries<
351336
352337 if (
353338 operationError . hasErrorLabel ( MongoErrorLabel . SystemOverloadedError ) &&
339+ operation . hasAspect ( Aspect . CURSOR_CREATING ) &&
354340 session != null &&
355341 session . isPinned &&
356342 ! session . inTransaction ( )
357343 ) {
358344 session . unpin ( { force : true } ) ;
359345 }
360346
347+ if ( operationError . hasErrorLabel ( MongoErrorLabel . SystemOverloadedError ) ) {
348+ const backoffMS = Math . random ( ) * Math . min ( MAX_BACKOFF_MS , BASE_BACKOFF_MS * 2 ** attempt ) ;
349+
350+ // if the backoff would exhaust the CSOT timeout, short-circuit.
351+ if ( timeoutContext . csotEnabled ( ) && backoffMS > timeoutContext . remainingTimeMS ) {
352+ throw error ;
353+ }
354+
355+ if ( topology . s . options . adaptiveRetries && ! topology . tokenBucket . consume ( RETRY_COST ) ) {
356+ throw error ;
357+ }
358+
359+ await setTimeout ( backoffMS ) ;
360+ }
361+
361362 if (
362363 topology . description . type === TopologyType . Sharded ||
363364 operationError . hasErrorLabel ( MongoErrorLabel . SystemOverloadedError )
0 commit comments