Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What could cause a "topology was destroyed" error when calling db.destroyDatabase with node.js mongodb native?

I am running some integration tests w/ the Node.js Mongodb native driver. Each test involves connecting to a database, verifying that it doesn't already exist (e.g. doesn't have any collections w/ documents), running a test, and then dropping the database. High-level code is as follows:

const runSafeTest = function runSafeTest(test) {
  async.waterfall([
    connectToMongo,
    throwIfDbExists,
    instantiateServerConnection,
    test
  ],
  function doneWaterfall(err, db) {
    db.dropDatabase(function(dbErr) {
      if (dbErr) throw dbErr
    });
  })
};

Every time db.dropDatabase() gets called it throws the following error:

MongoError: topology was destroyed

Not asking for specific debugging of the above code, but rather just a general question: what does a "topology was destroyed" error in MongoDB mean and what kinds of things could cause it? Have looked through the Mongo docs, the source code, and the other SO questions, but can't find a clear answer on what "topology was destroyed" means and how i might prevent it from manifesting in the testing approach we're using.

Thanks!

like image 982
Owen Avatar asked Oct 25 '15 16:10

Owen


1 Answers

On the off-chance anyone ever stumbles across this question, the problem was an errant db.close() call on the same db reference used later for db.dropDatabase(). IMO 'topology was destroyed' is an odd error for this (maybe 'socket closed'), but in this case was the problem.

like image 119
Owen Avatar answered Nov 03 '22 06:11

Owen