Skip to content

Commit

Permalink
Must not async wait inside termination for loop
Browse files Browse the repository at this point in the history
why:
  Async-waiting inside a `for` loop will switch to temination process
  which uncontrollably will modify the for-loop data base.
  • Loading branch information
mjfh committed Dec 6, 2024
1 parent 1634c0a commit 7118189
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions nimbus/sync/sync_sched.nim
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,13 @@ proc terminate[S,W](dsc: RunnerSyncRef[S,W]) =
for w in dsc.buddies.nextPairs:
if w.data.isRunning:
w.data.worker.ctrl.stopped = true
# Activate async job so it can finish
try:
waitFor sleepAsync termWaitPollingTime
except CancelledError:
trace "Shutdown: peer timeout was cancelled",
peer=w.data.worker.peer, nWorkers=dsc.buddies.len
else:
dsc.buddies.del w.key # this is OK to delete
# Activate async jobs so they can finish
try:
waitFor sleepAsync termWaitPollingTime
except CancelledError:
trace "Shutdown: peer timeout was cancelled", nWorkers=dsc.buddies.len

while dsc.daemonRunning:
# Activate async job so it can finish
Expand Down

0 comments on commit 7118189

Please sign in to comment.