mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-14 19:57:18 +00:00
prevent errors during node shutdown
This commit is contained in:
parent
82e0d81d61
commit
d5e3d57b5a
@ -128,17 +128,28 @@ method stop*(node: NodeProcess) {.base, async.} =
|
|||||||
error "failed to terminate process", errCode = $errCode
|
error "failed to terminate process", errCode = $errCode
|
||||||
|
|
||||||
trace "waiting for node process to exit"
|
trace "waiting for node process to exit"
|
||||||
let exitCode = await node.process.waitForExit(3.seconds)
|
var backoff = 8
|
||||||
if exitCode > 0:
|
while node.process.running().valueOr false:
|
||||||
|
backoff = min(backoff*2, 1024) # Exponential backoff
|
||||||
|
await sleepAsync(backoff)
|
||||||
|
|
||||||
|
let exitCode = node.process.peekExitCode().valueOr:
|
||||||
|
fatal "could not get exit code from process", error
|
||||||
|
return
|
||||||
|
|
||||||
|
if exitCode > 0 and exitCode != 143: # 143 = SIGTERM (initiated above)
|
||||||
error "failed to exit process, check for zombies", exitCode
|
error "failed to exit process, check for zombies", exitCode
|
||||||
|
|
||||||
trace "closing node process' streams"
|
|
||||||
await node.process.closeWait()
|
|
||||||
except CancelledError as error:
|
except CancelledError as error:
|
||||||
raise error
|
raise error
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
error "error stopping node process", error = e.msg
|
error "error stopping node process", error = e.msg
|
||||||
finally:
|
finally:
|
||||||
|
try:
|
||||||
|
trace "closing node process' streams"
|
||||||
|
await node.process.closeWait()
|
||||||
|
except:
|
||||||
|
discard
|
||||||
node.process = nil
|
node.process = nil
|
||||||
|
|
||||||
trace "node stopped"
|
trace "node stopped"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user