fix: don't release inflight semaphore when acquire is cancelled

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
This commit is contained in:
Chrysostomos Nanakos 2026-05-05 12:41:52 +03:00 committed by Arnaud
parent 80ea4c71cc
commit 17ef2d3b58
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA

View File

@ -107,16 +107,17 @@ proc send*(
let peer = b.peers[id]
await b.inflightSema.acquire()
await peer.send(msg)
try:
await peer.send(msg)
finally:
try:
b.inflightSema.release()
except AsyncSemaphoreError as err:
error "Failed to release semaphore", msg = err.msg
except CancelledError as error:
raise error
except CatchableError as err:
error "Error sending message", peer = id, msg = err.msg
finally:
try:
b.inflightSema.release()
except AsyncSemaphoreError as err:
error "Failed to release semaphore", msg = err.msg
proc handleWantList(
b: BlockExcNetwork, peer: NetworkPeer, list: WantList