Fixes nullref in networkPeer

This commit is contained in:
benbierens 2024-10-03 16:04:10 +02:00
parent b491906005
commit 67e5a3fc2e
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
1 changed files with 13 additions and 11 deletions

View File

@ -93,18 +93,20 @@ proc send*(b: BlockExcNetwork, id: PeerId, msg: pb.Message) {.async.} =
## Send message to peer
##
b.peers.withValue(id, peer):
try:
await b.inflightSema.acquire()
await peer[].send(msg)
except CancelledError as error:
raise error
except CatchableError as err:
error "Error sending message", peer = id, msg = err.msg
finally:
b.inflightSema.release()
do:
if not (id in b.peers):
trace "Unable to send, peer not found", peerId = id
return
let peer = b.peers[id]
try:
await b.inflightSema.acquire()
await peer.send(msg)
except CancelledError as error:
raise error
except CatchableError as err:
error "Error sending message", peer = id, msg = err.msg
finally:
b.inflightSema.release()
proc handleWantList(
b: BlockExcNetwork,