Fix Ctrl-C quitting (#1416)

This commit is contained in:
Tanguy 2022-12-06 11:51:33 +01:00 committed by GitHub
parent b77a4faa55
commit 4b180c89bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -687,14 +687,17 @@ when isMainModule:
## Setup shutdown hooks for this process.
## Stop node gracefully on shutdown.
proc asyncStopper(node: WakuNode) {.async.} =
await node.stop()
quit(QuitSuccess)
# Handle Ctrl-C SIGINT
proc handleCtrlC() {.noconv.} =
when defined(windows):
# workaround for https://github.com/nim-lang/Nim/issues/4057
setupForeignThreadGc()
notice "Shutting down after receiving SIGINT"
waitFor node.stop()
quit(QuitSuccess)
asyncSpawn asyncStopper(node)
setControlCHook(handleCtrlC)
@ -702,8 +705,7 @@ when isMainModule:
when defined(posix):
proc handleSigterm(signal: cint) {.noconv.} =
notice "Shutting down after receiving SIGTERM"
waitFor node.stop()
quit(QuitSuccess)
asyncSpawn asyncStopper(node)
c_signal(ansi_c.SIGTERM, handleSigterm)