Skip to content

Commit

Permalink
Fixes nullref in networkPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
benbierens committed Oct 3, 2024
1 parent b491906 commit 67e5a3f
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

Check warning on line 98 in codex/blockexchange/network/network.nim

View check run for this annotation

Codecov / codecov/patch

codex/blockexchange/network/network.nim#L98

Added line #L98 was not covered by tests

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:

Check warning on line 108 in codex/blockexchange/network/network.nim

View check run for this annotation

Codecov / codecov/patch

codex/blockexchange/network/network.nim#L105-L108

Added lines #L105 - L108 were not covered by tests
b.inflightSema.release()

proc handleWantList(
b: BlockExcNetwork,
Expand Down

0 comments on commit 67e5a3f

Please sign in to comment.