question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mongoose doesn't shut down gracefully

See original GitHub issue

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();

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:18

github_iconTop GitHub Comments

1reaction
pkantsedalovcommented, Jul 30, 2016

vkarpov15 it’s here

1reaction
jbachcommented, Dec 2, 2015

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I gracefully shutdown mongoose's connection pool?
Most documentation/tutorials state that to stop a connection (or pool of connections), I must use mongoose.disconnect() - which calls .close() ...
Read more >
Mongodb not shutting down via --shutdown command
When mongod gets the SIGTERM command(default signal of kill command is SIGTERM), it will shutdown the database gracefully.
Read more >
Graceful shutdown in NodeJS - HackerNoon
Graceful shutdown means when all your requests to the server is respond and not any data processing work left. You can not know...
Read more >
Graceful Shutdown | Best Practices | PM2 Documentation
Failed requests can be avoided with graceful shutdown and restart. This tutorial introduce you how to implement it. Graceful Shutdown. In a graceful...
Read more >
Let It Crash: Best Practices for Handling Node.js Errors on ...
Some strategies to gracefully shutdown the Node.js process and quickly restart your application after a catastrophic error terminates your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found