Long time MongoDB user here, first time posting on this forum.
I have several NodeJS servers that maintain long-running connections to our MongoDB backend. From time to time I’ve noticed that they seem to drop this connection, throwing a MongoServerSelection
error. I assume that perhaps this is due to load, or network fluctuations, or whatever.
Honestly, I don’t really care. What I want to happen is for the service to exit so that Kubernetes can restart it. But instead it just seems to hang until I notice and restart the container manually. I have process.on
handlers for both “uncaughtException” and “unhandledRejection” which call process.exit
, but these don’t seem to be working.
So what’s the best way in a node.js
app to either (1) reconnect across timeouts (the option to do this seems to have been removed recently) or (2) just exit the server in this situation? I’m using the latest version of the NodeJS MongoDB library.