-
Notifications
You must be signed in to change notification settings - Fork 285
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
Variable strength aborting #1215
Comments
You can attach data to the const reason = new Error('User clicked Kill Now')
reason.force = true
function aborted (event) {
if (event.target.reason.force) {
kill()
} else {
cancel()
}
} Or use two signals: let shuttingDown = false
process.on('SIGINT', () => {
if (!shuttingDown) {
// First interrupt, start graceful shutdown
shuttingDown = true
program.closed.then(() => { process.exit() })
gracefulController.abort()
} else {
// Second interrupt, kill everything now
forcefulController.abort()
}
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some systems distinguish between a graceful shutdown and a forceful termination. This distinction cannot be delivered through
AbortController
. It would be nice if the same channel could be used to deliver both.The current interface might extend to this cleanly, without breaking anything. The delivered
Event
could provide a boolean.force
indicating whether a forceful abort was requested or not.AbortController.prototype.abort()
could take the option{ force: true }
to request a forceful abort. A second call toabort()
could be allowed, for requesting forceful abort after a standard abort was already requested.2 levels of strength seem sufficient. I've never seen a use for further distinctions.
Some usage patterns.
This might be tied to a more forceful user control, eg Kill vs Cancel.
This might be useful where closing a connection can take a long time. The close logic can have retries to tolerate transient network errors, with delays between them. If the process drags on too long, terminate.
This is a common pattern in the CLI interface of servers. The first CTRL+C initiates a graceful shutdown: the server stops accepting new connections and waits for existing connections to complete normally. A second CTRL+C during graceful shutdown terminates all open connections without waiting for completion and shuts down immediately.
The text was updated successfully, but these errors were encountered: