Problems with mongoDB statefulsets in Kubernetes
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 15.2k
- Forks
- 3k
- Avg merge
- 16h 19m
- Merged PRs (30d)
- 167
Description
NodeBB version
v3.7.4
NodeBB git hash
No response
NodeJS version
v20.19.4
Installed NodeBB plugins
When a member of the mongodb replicaset is not available, nodebb fails to start and enters in crashloops. Both are happening with both connection string types so mongodb:// or mongodb+srv:// :
mongodb://nodebb:XXX@mongodb-0.mongodb-replicaset-svc,nodebb-stack-mongo-1.mongodb-replicaset-svc,mongo-2.mongodb-replicaset-svc/nodebb?tls=false&replicaSet=rs0&readPreference=primaryPreferred
I removed a pod from mongodb replicaset (2/3), and restarted a nodebb pod and it fails to start. Once I add it back, nodebb starts correctly.
I also simulated a node down when testing the connection string using mongosh from an other pod and it can connect even if a member does not exist. (The service is a headless one.):
mongodb://nodebb:XXX@mongodb-0.mongodb-replicaset-svc,nodebb-stack-mongo-1.mongodb-replicaset-svc,mongo-2.mongodb-replicaset-svc,mongo-3.mongodb-replicaset-svc/nodebb?tls=false&replicaSet=rs0&readPreference=primaryPreferred
For me this looks like a bug in the application or the mongodb driver, but it is quite problematic since that is not resilient to failure. I tried changing connectTimeoutMS=100000&serverSelectionTimeoutMS=100000 to the connection string but it does not help.
It could be a misconfiguration on the nodebb side but I would suspect the driver
Database type
No response
Database version
No response
Exact steps to cause this issue
No response
What you expected
No response
What happened instead
No response
Anything else?
No response
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
Reproduce the failure by restarting NodeBB while one MongoDB replica-set member is unavailable, using the connection strings and timeout settings from the report. Start by inspecting NodeBB's MongoDB connection handling and driver configuration; done means NodeBB starts and remains resilient when a replica-set member is down.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, kubernetes, mongodb, node.js
- Domain
- backend, databases, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100