Problems with mongoDB statefulsets in Kubernetes
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:[email protected],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:[email protected],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
Source: NodeBB/NodeBB