Skip to content

Commit

Permalink
Avoid waitFor in scheduler termination code
Browse files Browse the repository at this point in the history
why:
  Is reserved for main loop
  • Loading branch information
mjfh committed Dec 6, 2024
1 parent 7118189 commit 4fe205e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nimbus/nimbus_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ proc stop*(nimbus: NimbusNode, conf: NimbusConf) {.async, gcsafe.} =
if nimbus.peerManager.isNil.not:
await nimbus.peerManager.stop()
if nimbus.beaconSyncRef.isNil.not:
nimbus.beaconSyncRef.stop()
await nimbus.beaconSyncRef.stop()
if nimbus.metricsServer.isNil.not:
await nimbus.metricsServer.stop()

Expand Down
4 changes: 2 additions & 2 deletions nimbus/sync/beacon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ proc init*(
proc start*(desc: BeaconSyncRef): bool =
desc.startSync()

proc stop*(desc: BeaconSyncRef) =
desc.stopSync()
proc stop*(desc: BeaconSyncRef) {.async.} =
await desc.stopSync()

# ------------------------------------------------------------------------------
# End
Expand Down
8 changes: 4 additions & 4 deletions nimbus/sync/sync_sched.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ proc key(peer: Peer): ENode =
# Private functions
# ------------------------------------------------------------------------------

proc terminate[S,W](dsc: RunnerSyncRef[S,W]) =
proc terminate[S,W](dsc: RunnerSyncRef[S,W]) {.async.} =
## Request termination and wait for sub-tasks to finish
mixin runRelease

Expand All @@ -185,7 +185,7 @@ proc terminate[S,W](dsc: RunnerSyncRef[S,W]) =
while dsc.daemonRunning:
# Activate async job so it can finish
try:
waitFor sleepAsync termWaitPollingTime
await sleepAsync termWaitPollingTime
except CancelledError:
trace "Shutdown: daemon timeout was cancelled", nWorkers=dsc.buddies.len

Expand Down Expand Up @@ -481,9 +481,9 @@ proc startSync*[S,W](dsc: RunnerSyncRef[S,W]): bool =
return true


proc stopSync*[S,W](dsc: RunnerSyncRef[S,W]) =
proc stopSync*[S,W](dsc: RunnerSyncRef[S,W]) {.async.} =
## Stop syncing and free peer handlers .
dsc.terminate()
await dsc.terminate()


proc isRunning*[S,W](dsc: RunnerSyncRef[S,W]): bool =
Expand Down

0 comments on commit 4fe205e

Please sign in to comment.