mongoose: Mongoose doesn't shut down gracefully

Mongoose never lets the node event loop clear, even after disconnect is called. This stops node from exiting gracefully (i.e. without calling process.exit()) Other server modules allow node to shutdown after it’s respective .close() or .shutdown() is called, including Restify, Express, etc. Mongoose, however, holds the application open.

This application never exits:

//Boilerplate
var mongoose = require('mongoose');
var db = mongoose.connection;
db.on('error', function(err) {
    console.log('Mongoose connection error: ' + err);
});

//connect
mongoose.connect("localhost");

//disconnect
mongoose.disconnect();

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 1
  • Comments: 18

Commits related to this issue

Most upvoted comments

This is still an issue for me. Mongoose 5.0.4, Node 4.2.1. After running disconnect(), the process keeps running. Is this the same issue as https://github.com/Automattic/mongoose/issues/3358?