Random failure to connect to MongoDB



My build failed because of the error:
MongoError: server localhost:27017 sockets closed (see attachment)

A rebuild fixed it. Any ideas why this might happen?


Did this happen at the beginning, at the end or in the middle of your test suite? Are other tests using MongoDB as well?


It happened right at the beginning of the test suite. And yes, all other tests use mongoDB as well. After the first one everything else ran fine.


Could it be that the DB was not yet ready when the very first test ran?

I am not sure about Mongo, but with Elasticsearch there is an API endpoint that allows the user to check the status of the DB engine. Is there something in Mongo that you could use for that purpose?

The idea would be to actively wait for Mongo to become fully available and see if that helps.


Sorry for the late revert. We are in fact checking if mongoose has successfully connected to Mongo before running our tests. Thus we wonder why connection failure still happens.


So the check that runs before the tests succeeds while actually connecting to the DB during the test fails? Are you sure both tests are connecting to the same DB?


any progress on this? I’m having the same problem in some of my tests using jest

closed #8