From 273a912ae0d7c8d344d76a8a334fa695640d447c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Thu, 28 May 2020 03:14:01 +0200 Subject: [PATCH] Eth2Node.stop(): trace msg on timeout --- beacon_chain/eth2_network.nim | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index 2c97eaef6..e20d3ee4d 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -1,6 +1,6 @@ import # Std lib - typetraits, strutils, os, random, algorithm, + typetraits, strutils, os, random, algorithm, sequtils, options as stdOptions, net as stdNet, # Status libs @@ -738,14 +738,17 @@ proc start*(node: Eth2Node) {.async.} = traceAsyncErrors node.discoveryLoop proc stop*(node: Eth2Node) {.async.} = - # Ignore errors in futures, since we're shutting down. - # Use a timer to avoid hangups. - discard await one(sleepAsync(5.seconds), - allFutures(@[ - node.discovery.closeWait(), - node.switch.stop(), - ]) - ) + # Ignore errors in futures, since we're shutting down (but log them on the + # TRACE level, if a timeout is reached). + let + waitedFutures = @[ + node.discovery.closeWait(), + node.switch.stop(), + ] + timeout = 5.seconds + completed = await withTimeout(allFutures(waitedFutures), timeout) + if not completed: + trace "Eth2Node.stop(): timeout reached", timeout, futureErrors = waitedFutures.filterIt(it.error != nil).mapIt(it.error.msg) proc init*(T: type Peer, network: Eth2Node, info: PeerInfo): Peer = new result