kartikk221 / hyper-express

High performance Node.js webserver with a simple-to-use API powered by uWebsockets.js under the hood.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graceful shutdown

benjaco opened this issue · 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.

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.

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.

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

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