Skip to content

Commit

Permalink
Revert "Handle Ctrl+C graceful shutdown."
Browse files Browse the repository at this point in the history
  • Loading branch information
web3-developer committed Sep 19, 2024
1 parent 0b15fe0 commit c545165
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
26 changes: 6 additions & 20 deletions fluffy/fluffy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func optionToOpt[T](o: Option[T]): Opt[T] =
else:
Opt.none(T)

proc run(config: PortalConf): PortalNode {.raises: [CatchableError].} =
proc run(config: PortalConf) {.raises: [CatchableError].} =
setupLogging(config.logLevel, config.logStdout, none(OutFile))

notice "Launching Fluffy", version = fullVersionStr, cmdParams = commandLineParams()
Expand Down Expand Up @@ -166,6 +166,7 @@ proc run(config: PortalConf): PortalNode {.raises: [CatchableError].} =
dataDir: string config.dataDir,
storageCapacity: config.storageCapacityMB * 1_000_000,
)

node = PortalNode.new(
config.network,
portalNodeConfig,
Expand Down Expand Up @@ -251,7 +252,7 @@ proc run(config: PortalConf): PortalNode {.raises: [CatchableError].} =

setupRpcServer(rpcWsServer)

return node
runForever()

when isMainModule:
{.pop.}
Expand All @@ -261,21 +262,6 @@ when isMainModule:
)
{.push raises: [].}

let node =
case config.cmd
of PortalCmd.noCommand:
run(config)

# Ctrl+C handling
proc controlCHandler() {.noconv.} =
when defined(windows):
# workaround for https://github.com/nim-lang/Nim/issues/4057
setupForeignThreadGc()

notice "Got interrupt, shutting down Fluffy..."
node.stop()
quit QuitSuccess

setControlCHook(controlCHandler)

runForever()
case config.cmd
of PortalCmd.noCommand:
run(config)
2 changes: 1 addition & 1 deletion fluffy/network/beacon/beacon_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ proc start*(lightClient: LightClient) =

proc stop*(lightClient: LightClient) =
info "Stopping beacon light client"
lightClient.manager.stop()
discard lightClient.manager.stop()

proc resetToFinalizedHeader*(
lightClient: LightClient,
Expand Down
7 changes: 4 additions & 3 deletions fluffy/network/beacon/beacon_light_client_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ proc start*(self: var LightClientManager) =
doAssert self.loopFuture == nil
self.loopFuture = self.loop()

proc stop*(self: var LightClientManager) =
proc stop*(self: var LightClientManager) {.async: (raises: []).} =
## Stop light client manager's loop.
if not self.loopFuture.isNil():
self.loopFuture.cancelSoon()
if self.loopFuture != nil:
await noCancel self.loopFuture.cancelAndWait()
self.loopFuture = nil

0 comments on commit c545165

Please sign in to comment.