Random failure to connect to MongoDB

mongo
nodejs

#1

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?


#2

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


#3

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.


#4

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.


#5

Hi,
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.


#6

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?


#7

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


#8