Frequent "operation was interrupted" errors when running multiple MongoMemoryReplSets in parallel
#995 aperta il 8 giu 2026
Metriche repository
- Star
- (2828 star)
- Metriche merge PR
- (Metriche PR in attesa)
Descrizione
Versions
- NodeJS: v24.15.0
- mongodb-memory-server-*: 11.1.0
- mongodb(the binary version): 0.0.0
- mongodb(the js package): 0.0.0
- system: Linux (GitHub Actions ubuntu-latest), MacOS
package: mongo-memory-server
What is the Problem?
We use mongodb-memory-server to run tests for our MongoDB operations in our services, usually with great success. But recently, due to some changes to how we do our builds, we've been seeing many tests fail with MongoWriteConcernError: operation was interrupted.
Poking around I figured out that this only happens when multiple test runs happen in parallel on the same machine (for example two different services at the same time or in my tests just pnpm test & ; pnpm test).
We use Vitest with a global repl set.
#911 looks related but was never debugged.
Code Example
import { MongoMemoryReplSet } from 'mongodb-memory-server';
export async function setup() {
const mongod = await MongoMemoryReplSet.create({ replSet: { count: 3 } });
process.env.MONGO_URI = mongod.getUri();
return async () => {
await mongod.stop();
};
}
Debug Output
This output was acquired by running pnpm test >1 2>&1 & ; pnpm test & ; pnpm test & ; pnpm test& ; pnpm test& ; pnpm test& ; pnpm test& ; pnpm test. Some of the other concurrent test runs succeeded, some failed as well with the same error.
Checking the the mongod.getUri() clearly showed that all those projects had separate instances (different ports), so it's surprising to me that they are affected like this.
(log is too large for embedding it directly) https://gist.github.com/nora-heydecker-axa/30aeb13db767149f1d284d62399b7ade
Do you know why it happenes?
no, but some things I found in the logs that seem relevant:
2026-06-08T12:44:58.275Z MongoMS:MongoInstance Mongo[63369]: stdoutHandler: ""{"t":{"$date":"2026-06-08T14:44:58.275+02:00"},"s":"I", "c":"REPL", "id":21216, "ctx":"ReplCoord-1","msg":"Member is now in state DOWN","attr":{"hostAndPort":"127.0.0.1:63372","heartbeatMessage":"no response within election timeout period"}}""
2026-06-08T12:44:58.279Z MongoMS:MongoInstance Mongo[63369]: stdoutHandler: ""{"t":{"$date":"2026-06-08T14:44:58.279+02:00"},"s":"I", "c":"REPL", "id":21216, "ctx":"ReplCoord-6","msg":"Member is now in state DOWN","attr":{"hostAndPort":"127.0.0.1:63371","heartbeatMessage":"no response within election timeout period"}}""
2026-06-08T12:44:58.282Z MongoMS:MongoInstance Mongo[63369]: stdoutHandler: ""{"t":{"$date":"2026-06-08T14:44:58.279+02:00"},"s":"I", "c":"REPL", "id":21809, "ctx":"ReplCoord-6","msg":"Can't see a majority of the set, relinquishing primary"}
{"t":{"$date":"2026-06-08T14:44:58.279+02:00"},"s":"I", "c":"REPL", "id":21475, "ctx":"ReplCoord-6","msg":"Stepping down from primary in response to heartbeat"}
{"t":{"$date":"2026-06-08T14:44:58.279+02:00"},"s":"I", "c":"REPL", "id":21343, "ctx":"RstlKillOpThread","msg":"Starting to kill user operations"}
shortly before the test failed. I don't know why that server would suddenly be down, but that seems like it would cause the interruption.
Our tests don't do anything crazy, this is a small package. We create a few indices, run a few transactions, all with single-digit amounts of documents.