Skip to content

Commit

Permalink
Fix: null-ref in networkPeer (#937)
Browse files Browse the repository at this point in the history
* Fixes nullref in networkPeer

* Removes inflight semaphore

* Revert "Removes inflight semaphore"

This reverts commit 26ec15c.
  • Loading branch information
benbierens authored Oct 7, 2024
1 parent 0ea8cfb commit 17f0988
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions codex/blockexchange/network/network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 17f0988

Please sign in to comment.