Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop accepting new connections #4355

Open
ORESoftware opened this issue Mar 12, 2024 · 1 comment
Open

stop accepting new connections #4355

ORESoftware opened this issue Mar 12, 2024 · 1 comment

Comments

@ORESoftware
Copy link

ORESoftware commented Mar 12, 2024

Details

Here:
https://stackoverflow.com/questions/78144749/using-node-js-how-to-stop-new-requests-before-closing-existing-ones

The question is:

  1. is this the best way to stop accepting new connections before ending the existing connections/requests?
  2. how are "idle" connections defined?

Node.js version

version 20+

Example code

const server = app.listen(3900, '0.0.0.0', () => {
  console.log('listening...');
});

process.once('SIGINT', () => {

  console.log('got SIGINT.')

  setTimeout(() => {
    console.log('ending process due to SIGINT + subsequent Timeout.')
    process.exit(0);
  }, 3000);

  server.closeIdleConnections();
  server.closeAllConnections();
  server.close(err => {
    if (err) {
      console.error(err);
    }
    console.log('closed server, and now shutting down due to SIGINT.')
    process.exit(0);
  });
});

Operating system

darwin/linux

Scope

http

Module and version

http

@ORESoftware
Copy link
Author

@ORESoftware ORESoftware changed the title Graceful shutdown of Node.js server - stop accepting new connections stop accepting new connections Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant