hyper-express icon indicating copy to clipboard operation
hyper-express copied to clipboard

Graceful shutdown

Open benjaco opened this issue 5 months ago • 2 comments

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 avatar Feb 01 '24 00:02 benjaco

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 avatar Feb 01 '24 01:02 kartikk221

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.

kartikk221 avatar Feb 23 '24 17:02 kartikk221

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

benjaco avatar Mar 08 '24 18:03 benjaco

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

kartikk221 avatar Mar 25 '24 21:03 kartikk221