-
-
Notifications
You must be signed in to change notification settings - Fork 183
Description
Versions
- NodeJS: 22.15.1
- mongodb-memory-server-*: 10.1.4
- mongodb(the binary version): 8.0.9
- mongodb(the js package): 6.13.1
- mongoose: 8.9.5
- system: Linux (Ubuntu 24.04.2 LTS (Noble Numbat), running in Jenkins CI inside Docker)
package: mongo-memory-server
What is the Problem?
When running daily builds on our Jenkins CI server (where each build runs in a clean Docker container), the MongoDB binary is downloaded fresh during every build. We've observed that the MongoDB binary download intermittently stalls or hangs at 0%, and never progresses:
Downloading MongoDB “8.0.9”: 0% (0mb / 95.7mb)
This causes CI builds to fail or time out unnecessarily.
Code Example
const { MongoMemoryServer } = require('mongodb-memory-server');
const MONGO_DB_VERSION = '8.0.9';
const MONGO_DB_PORT = 53208;
const mongoOptions = {
binary: { version: MONGO_DB_VERSION },
instance: { port: MONGO_DB_PORT }
};
mongoServer = await MongoMemoryServer.create(mongoOptions);
if (!mongoServer) {
throw new Error('Failed to start mongodb-memory-server - in-memory MongoDB server');
}
try {
const mongoUri = mongoServer.getUri();
await mongodb.MongoClient.connect(mongoUri);
console.log(`Successfully Connected to in-memory MongoDB server at ${mongoUri}`);
} catch (err) {
console.error(`Error connecting to in-memory MongoDB server: ${err} with stack: ${err.stack}`);
throw err;
}
Debug Output
Downloading MongoDB "8.0.9": 0% (0mb / 95.7mb)
// No further progress observed; hangs indefinitely and eventually the mocha test times out.
Do you know why it happens?
The exact cause isn’t clear, but it’s likely due to network flakiness or bandwidth throttling on the CI infrastructure. Since there’s no retry or timeout logic, the download simply stalls.
Suggested Fix
Would it be possible to add retry logic to MongoBinaryDownload.httpDownload()?
Proposal:
• Add a new maxDownloadRetries configuration option
• Implement exponential backoff with jitter between each retry attempt
• Optionally: configurable base delay
This would make the downloads more resilient in CI environments and reduce false build failures due to transient network issues.