Skip to content

Commit 7d5f45c

Browse files
committed
restore signal state after waitSignal
1 parent 341495e commit 7d5f45c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

beacon_chain/process_state.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ proc waitStopSignals*(_: type ProcessState) {.async: (raises: [CancelledError]).
145145
##
146146
## Only one thread should ever listen for stop signals this way.
147147

148+
# Ensure other threads don't cause a crash, in case the application did not
149+
# already call it
150+
ProcessState.setupStopHandlers()
151+
148152
let
149153
sigint = waitSignal(chronos.SIGINT)
150154
sigterm = waitSignal(chronos.SIGTERM)
@@ -164,10 +168,15 @@ proc waitStopSignals*(_: type ProcessState) {.async: (raises: [CancelledError]).
164168

165169
processState.store(ProcessState.Stopping, moRelaxed)
166170
finally:
171+
# waitSignal sometimes overwrites signal handlers:
172+
# https://github.com/status-im/nim-chronos/issues/581
173+
ProcessState.setupStopHandlers()
174+
167175
# Might be finished already, which is fine..
168176
await noCancel sigint.cancelAndWait()
169177
await noCancel sigterm.cancelAndWait()
170178

179+
171180
proc running*(_: type ProcessState): bool =
172181
processState.load(moRelaxed) == ProcessState.Running
173182

0 commit comments

Comments
 (0)