typegoose / typegoose/mongodb-memory-server
Frequent "operation was interrupted" errors when running multiple MongoMemoryReplSets in parallel
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.8k
- Forks
- 191
- Avg merge
- 4h 25m
- Merged PRs (30d)
- 10
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the provided MongoMemoryReplSet setup and concurrent pnpm test runs, then review the linked debug output and related issue #911. Trace why separate three-member replica sets lose members or majority during parallel execution. Done means the interruption is explained and the parallel test scenario no longer produces the reported errors, with regression coverage where the existing test structure permits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, typescript
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100