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

Graceful shutdown #226

Closed
benjaco opened this issue Feb 1, 2024 · 4 comments
Closed

Graceful shutdown #226

benjaco opened this issue Feb 1, 2024 · 4 comments

Comments

@benjaco
Copy link
Contributor

benjaco commented Feb 1, 2024

Trying to figure out how to do a graceful shutdown

The only function i can see it the .close described in docs/Server.md, but that just kills the server and returns a bool

The expected functionality is that it stop accepting connections when .close, and then returnes a promise there resolves when there's no more active clients.

Any way of doing this would work, thats just express's implementation as far as i know.

@benjaco benjaco changed the title Gracefull shotdown Graceful shutdown Feb 1, 2024
@kartikk221
Copy link
Owner

Hey, this is a good idea and can certainly be implemented but it will be done in a non breaking way as the current Server.close() method is meant to be synchronous and thus making it asynchronous may break certain applications.

@kartikk221
Copy link
Owner

Hey, which signature do you think would be a better API going forward:

// This simply adds the `graceful` argument and changes the return type to now potentially return a Promise
Server.close(graceful: boolean): void | Promise<void>

// This is a different alternative method to `.close()` but maintains a proper return signature and meaningful name
Server.shutdown(): Promise<void>

I understand none of the above may be 100% compatible with Express.js but the compatibility gaps are to be reduced in the next major version update.

@benjaco
Copy link
Contributor Author

benjaco commented Mar 8, 2024

That decision would I leave completely up to you, it sound like that its going to change for the next version regardless to bridge the compatible gap

@kartikk221
Copy link
Owner

The Server.shutdown() method has been implemented in the latest version 6.15.0 which should resolve your issue.

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

2 participants