intro-mongo-db icon indicating copy to clipboard operation
intro-mongo-db copied to clipboard

MongoError: server is closed

Open chrisueda opened this issue 4 years ago • 3 comments

Getting this error MongoError: server is closed right before the should have correct fields user test when running this command: yarn test exercises/models/__test__/user.spec.js. Strangely if I remove the previous betaUser should default to false test, the error goes away.

Full error:


    MongoError: server is closed

      at executeWriteOperation (node_modules/mongodb/lib/core/sdam/server.js:439:14)
      at Server.insert (node_modules/mongodb/lib/core/sdam/server.js:372:5)
      at Object.callback (node_modules/mongodb/lib/core/sdam/topology.js:938:15)
      at processWaitQueue (node_modules/mongodb/lib/core/sdam/topology.js:1036:21)
      at NativeTopology.selectServer (node_modules/mongodb/lib/core/sdam/topology.js:440:5)
      at executeWriteOperation (node_modules/mongodb/lib/core/sdam/topology.js:906:12)
      at NativeTopology.insert (node_modules/mongodb/lib/core/sdam/topology.js:595:5)
      at NativeTopology.insert (node_modules/mongodb/lib/topologies/native_topology.js:54:11)
      at insertDocuments (node_modules/mongodb/lib/operations/common_functions.js:259:19)
      at InsertOneOperation.execute (node_modules/mongodb/lib/operations/insert_one.js:26:5)
      at executeOperation (node_modules/mongodb/lib/operations/execute_operation.js:77:17)
      at Collection.Object.<anonymous>.Collection.insertOne (node_modules/mongodb/lib/collection.js:516:10)
      at NativeCollection.<computed> [as insertOne] (node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:171:28)
      at model.Object.<anonymous>.Model.$__handleSave (node_modules/mongoose/lib/model.js:273:33)
      at model.Object.<anonymous>.Model.$__save (node_modules/mongoose/lib/model.js:337:8)
      at node_modules/kareem/index.js:278:20```

chrisueda avatar Mar 24 '20 22:03 chrisueda

Hey there, I struggle with similar issues - I traced it back to connections pooling, and closing early.

Happens on the solution branch too.

Playing around with the following seems to help somewhat

mongoose.connect('mongodb://localhost/', {
    poolSize: 15,
    useNewUrlParser: true,
    useUnifiedTopology: true
  }

throwing error: MongoError: server is closed

without useUnifiedTopology it throws: MongoError: pool is draining, new operations prohibited

b3nk3 avatar Mar 30 '20 17:03 b3nk3

Getting this error MongoError: server is closed right before the should have correct fields user test when running this command: yarn test exercises/models/__test__/user.spec.js. Strangely if I remove the previous betaUser should default to false test, the error goes away.

Full error:


    MongoError: server is closed

      at executeWriteOperation (node_modules/mongodb/lib/core/sdam/server.js:439:14)
      at Server.insert (node_modules/mongodb/lib/core/sdam/server.js:372:5)
      at Object.callback (node_modules/mongodb/lib/core/sdam/topology.js:938:15)
      at processWaitQueue (node_modules/mongodb/lib/core/sdam/topology.js:1036:21)
      at NativeTopology.selectServer (node_modules/mongodb/lib/core/sdam/topology.js:440:5)
      at executeWriteOperation (node_modules/mongodb/lib/core/sdam/topology.js:906:12)
      at NativeTopology.insert (node_modules/mongodb/lib/core/sdam/topology.js:595:5)
      at NativeTopology.insert (node_modules/mongodb/lib/topologies/native_topology.js:54:11)
      at insertDocuments (node_modules/mongodb/lib/operations/common_functions.js:259:19)
      at InsertOneOperation.execute (node_modules/mongodb/lib/operations/insert_one.js:26:5)
      at executeOperation (node_modules/mongodb/lib/operations/execute_operation.js:77:17)
      at Collection.Object.<anonymous>.Collection.insertOne (node_modules/mongodb/lib/collection.js:516:10)
      at NativeCollection.<computed> [as insertOne] (node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:171:28)
      at model.Object.<anonymous>.Model.$__handleSave (node_modules/mongoose/lib/model.js:273:33)
      at model.Object.<anonymous>.Model.$__save (node_modules/mongoose/lib/model.js:337:8)
      at node_modules/kareem/index.js:278:20```

PR #17 seems to be providing the most consistent results so far.

b3nk3 avatar Mar 30 '20 17:03 b3nk3

PR #17 ftw

mkelley33 avatar Apr 21 '20 03:04 mkelley33