From c5451659fa429ee9e5db69da0b44a933241060e9 Mon Sep 17 00:00:00 2001 From: web3-developer <51288821+web3-developer@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:32:31 +0800 Subject: [PATCH] Revert "Handle Ctrl+C graceful shutdown." --- fluffy/fluffy.nim | 26 +++++-------------- fluffy/network/beacon/beacon_light_client.nim | 2 +- .../beacon/beacon_light_client_manager.nim | 7 ++--- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/fluffy/fluffy.nim b/fluffy/fluffy.nim index bcd09161b..cdb4933d4 100644 --- a/fluffy/fluffy.nim +++ b/fluffy/fluffy.nim @@ -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() @@ -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, @@ -251,7 +252,7 @@ proc run(config: PortalConf): PortalNode {.raises: [CatchableError].} = setupRpcServer(rpcWsServer) - return node + runForever() when isMainModule: {.pop.} @@ -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) diff --git a/fluffy/network/beacon/beacon_light_client.nim b/fluffy/network/beacon/beacon_light_client.nim index 381cbe594..a806860d1 100644 --- a/fluffy/network/beacon/beacon_light_client.nim +++ b/fluffy/network/beacon/beacon_light_client.nim @@ -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, diff --git a/fluffy/network/beacon/beacon_light_client_manager.nim b/fluffy/network/beacon/beacon_light_client_manager.nim index 882b218c8..36fc5db4c 100644 --- a/fluffy/network/beacon/beacon_light_client_manager.nim +++ b/fluffy/network/beacon/beacon_light_client_manager.nim @@ -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