Skip to content

Commit

Permalink
chore: add Cancelled exception to GetConn
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Feb 19, 2025
1 parent a978660 commit 63c2533
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion libp2p/protocols/pubsub/pubsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ method getOrCreatePeer*(
peer[].codec = protoNegotiated
return peer[]

proc getConn(): Future[Connection] {.async: (raises: [GetConnDialError]).} =
proc getConn(): Future[Connection] {.async: (raises: [CancelledError, GetConnDialError]).} =
try:
return await p.switch.dial(peerId, protosToDial)
except CancelledError as exc:
raise exc
except CatchableError as e:
raise (ref GetConnDialError)(parent: e)

Expand Down
2 changes: 1 addition & 1 deletion libp2p/protocols/pubsub/pubsubpeer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type
PubSubPeerEvent* = object
kind*: PubSubPeerEventKind

GetConn* = proc(): Future[Connection] {.async: (raises: [GetConnDialError]).}
GetConn* = proc(): Future[Connection] {.async: (raises: [CancelledError, GetConnDialError]).}
DropConn* = proc(peer: PubSubPeer) {.gcsafe, raises: [].}
# have to pass peer as it's unknown during init
OnEvent* = proc(peer: PubSubPeer, event: PubSubPeerEvent) {.gcsafe, raises: [].}
Expand Down
6 changes: 4 additions & 2 deletions tests/pubsub/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ randomize()
type TestGossipSub* = ref object of GossipSub

proc getPubSubPeer*(p: TestGossipSub, peerId: PeerId): PubSubPeer =
proc getConn(): Future[Connection] {.async: (raises: [GetConnDialError]).} =
try:
proc getConn(): Future[Connection] {.async: (raises: [CancelledError, GetConnDialError]).} =
try:
return await p.switch.dial(peerId, GossipSubCodec_12)
except CancelledError as exc:
raise exc
except CatchableError as e:
raise (ref GetConnDialError)(parent: e)

Expand Down

0 comments on commit 63c2533

Please sign in to comment.