Connection Pool Size Limits in Meteor: Unresolved Exhaustion Behavior
0 reputation · 13 Apr 2023, 08:10 UTC
0 reputation · 13 Apr 2023, 08:10 UTC
Diagnose intermittent "MongoError: connection pool exhausted" incidents in a Meteor application.
Current Meteor releases default to 10 MongoDB connections per process, adjustable via MONGO_CONNECTION_POOL_SIZE. The pool exhaustion error propagates to clients without built‑in back‑pressure or retry logic.
While the environment variable can increase the pool, it is unclear whether there is an upper practical limit or whether Meteor provides graceful degradation when the pool is exceeded. The behavior under sustained high concurrency remains undocumented.
MONGO_CONNECTION_POOL_SIZE above the default ever lead to unstable behavior or crashes?32775 reputation · 13 Apr 2023, 13:59 UTC
The observed “connection pool exhausted” errors occur when the rate of MongoDB requests exceeds the rate at which connections are returned to the pool. Because Meteor does not apply back‑pressure, the queue grows until waitQueueTimeoutMs is hit, producing the error seen by clients.
console.log(process.env.MONGO_URL) or inspect MongoInternals.defaultRemoteCollectionDriver().mongo.clientOptions at startup.db.serverStatus().connPoolStats on the MongoDB instance under load to see active, available, and waiting connections.To decide whether to increase the pool size or lower waitQueueTimeoutMs, confirm the observed timeout pattern: are you seeing queued delays that later succeed, or immediate timeout errors? This detail determines whether raising the pool size or tuning the timeout is the appropriate next step.
Use comments to ask for clarification. Post a solution as an answer.
32,775 reputation · 13 Apr 2023, 19:50 UTC
One clarification that changes the arithmetic: MONGO_CONNECTION_POOL_SIZE is not a per-process total. In Meteor releases that pass it to the Node driver, it becomes the per-server pool size (historically poolSize, later maxPoolSize). Against a replica set, one Meteor process can therefore open up to that many sockets to each eligible member, and a separate client created for MONGO_OPLOG_URL adds its own pool. Raising the variable can move the failure from pool exhaustion to MongoDB's maxIncomingConnections or the OS file-descriptor limit. The practical follow-up is to confirm the bundled driver version and whether waitQueueTimeoutMS is set: that determines whether sustained concurrency shows queuing latency or immediate checkout errors. Verify against the same topology you run in production, since standalone, replica set, and mongos account for connections differently.