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

Attempt to terminate via SIGINT + SIGTERM; should fix (or at least improve) #1479 #732

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

---

## [6.0.4] 2024-03-27

### Fixed

- Make a best effort attempt to terminate the process via `SIGINT` + `SIGTERM` termination signals; should fix (or at least improve) #1479
- Sandbox running via CLI will now forcefully terminate itself after 5 seconds if the termination routine has stalled out or takes too long
- Thanks @lpsinger + @courey!

---

## [6.0.3] 2024-03-25

### Changed
Expand Down
25 changes: 21 additions & 4 deletions src/cli/_stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ let sandbox = require('../')
module.exports = function handleStdin (params) {
let { rehydrate, update, watcher } = params

let ending = false
let timeout

// Listen for important keystrokes
emitKeypressEvents(process.stdin)
if (process.stdin.isTTY) {
Expand Down Expand Up @@ -34,15 +37,29 @@ module.exports = function handleStdin (params) {
})
}
if (key.sequence === '\u0003' || key.sequence === '\u0004') {
if (watcher) {
watcher.close().then(end)
}
else end()
terminate('ctrl^c')
}
})

process.on('SIGINT', terminate)
process.on('SIGTERM', terminate)

function terminate (via) {
if (ending) return
else ending = true

timeout = setTimeout(() => {
update.err(`Process failed to gracefully exit in 5 seconds via ${via}, forcefully terminated`)
process.exit(1)
}, 5000)

if (watcher) watcher.close().then(end)
else end()
}

function end () {
sandbox.end(function (err) {
if (timeout) clearTimeout(timeout)
if (err) {
update.err(err)
process.exit(1)
Expand Down
Loading