Files
mongo/jstests/libs/retryable_mongo.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

21 lines
560 B
JavaScript

/**
* Construct a new Mongo instance, retrying multiple times in case of failure.
* @param {...any} args to be passed onto the Mongo constructor.
* @returns New Mongo instance
* @throws After maximum retries have exceeded.
*/
export default function newMongoWithRetry(...args) {
const MAX_RETRIES = 10;
let retryCount = 0;
while (true) {
try {
return globalThis.Mongo.apply(this, args);
} catch (error) {
if (++retryCount >= MAX_RETRIES) {
throw error;
}
}
}
}