Answer the question
In order to leave comments, you need to log in
Why is Mongoose destroying the connection pool?
Hello!
Faced such a problem: at an unpredictable moment, the Node.js process, when requested to search in the database, mongoose
crashes with an error
MongoError: pool destroyed
at Pool.write (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:853:8)
at _command (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/wireprotocol/command.js:127:10)
at command (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/wireprotocol/command.js:27:5)
at Object.query (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/wireprotocol/query.js:57:3)
at Server.query (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/topologies/server.js:639:16)
at FindOperation.execute (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/operations/find.js:24:12)
at topology.selectServer (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/operations/execute_operation.js:164:17)
at Server.selectServer (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/topologies/server.js:827:3)
at Server.selectServer (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/topologies/topology_base.js:363:32)
at executeWithServerSelection (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/operations/execute_operation.js:150:12)
at executeOperation (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/operations/execute_operation.js:81:16)
at Cursor._initializeCursor (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:545:7)
at Cursor._initializeCursor (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:191:11)
at nextFunction (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:748:10)
at Cursor._next (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/core/cursor.js:202:5)
at fetchDocs (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/operations/to_array.js:27:14) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }
MongoDB
alive and healthcheck
reports on the status The healthy
Node.js
reconnection occurs normally. After a while, the process crashes again. mongoose
are all default, except for poolSize
which is set to 250
. Node.js
and MongoDB
in Docker
using docker-compose
. Node.js
is built from node:10
MongoDB
-- mongo:latest
(currently: 4.2.3
) Version mongoose
5.7.5
Answer the question
In order to leave comments, you need to log in
Ivan Chernyshev , there is a suspicion that you are doing db.close() somewhere before the operation is completed.
This is how the pool works https://mongodb.github.io/node-mongodb-native/core...
After reading the sources https://github.com/mongodb-js/mongodb-core/blob/ma... you can understand that the pool is destroyed when the sockets run out or the limit of reconnect attempts occurs.
Mongoose is quite old, they fixed bugs there. Try updating it.
Also enable debugging in mongus.
mongoose.set('debug', true)
poolSize which is set to 250.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question