From 1edb37c8f594a233f8ae1770c1a086f662a9540b Mon Sep 17 00:00:00 2001 From: Arnaud Date: Thu, 30 Oct 2025 05:51:08 +0100 Subject: [PATCH] Prevent seg fault when trying to close the discovery while it was not started --- codex/discovery.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codex/discovery.nim b/codex/discovery.nim index 4a211c20..9ff89caf 100644 --- a/codex/discovery.nim +++ b/codex/discovery.nim @@ -43,6 +43,7 @@ type Discovery* = ref object of RootObj # record to advertice node connection information, this carry any # address that the node can be connected on dhtRecord*: ?SignedPeerRecord # record to advertice DHT connection information + isStarted: bool proc toNodeId*(cid: Cid): NodeId = ## Cid to discovery id @@ -203,10 +204,15 @@ proc start*(d: Discovery) {.async: (raises: []).} = try: d.protocol.open() await d.protocol.start() + d.isStarted = true except CatchableError as exc: error "Error starting discovery", exc = exc.msg proc stop*(d: Discovery) {.async: (raises: []).} = + if not d.isStarted: + warn "Discovery not started, skipping stop" + return + try: await noCancel d.protocol.closeWait() except CatchableError as exc: