I have an ExpressJs server (version 4.X) and I need to stop the server correctly.
Since some requests can last a long time (1-2 seconds), I have to reject new connections and wait for all current requests to finish. Killing a server in the middle of some tasks can cause the server to be in an unstable state.
I tried the following code:
var app = express();
var server = https.createServer(options, app);
server.listen(3000);
process.on('SIGINT', function() {
server.close();
});
However, this code does not close keep-alive connections, and some clients may communicate for a long time.
So how can I properly close all connections?
source
share