Skip to content

Commit e1a3b47

Browse files
committed
bail early on CSOT before consuming a token
1 parent 3bf1442 commit e1a3b47

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/operations/execute_operation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,17 @@ async function executeOperationWithRetries<
324324
}
325325

326326
if (operationError.hasErrorLabel(MongoErrorLabel.SystemOverloadedError)) {
327-
if (topology.s.options.adaptiveRetries && !topology.tokenBucket.consume(RETRY_COST)) {
328-
throw error;
329-
}
330-
331327
const backoffMS = Math.random() * Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** attempt);
332328

333329
// if the backoff would exhaust the CSOT timeout, short-circuit.
334330
if (timeoutContext.csotEnabled() && backoffMS > timeoutContext.remainingTimeMS) {
335331
throw error;
336332
}
337333

334+
if (topology.s.options.adaptiveRetries && !topology.tokenBucket.consume(RETRY_COST)) {
335+
throw error;
336+
}
337+
338338
await setTimeout(backoffMS);
339339
}
340340

0 commit comments

Comments
 (0)