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