Skip to content

Commit 147da5f

Browse files
author
Darioush Jalali
committed
peer/network: move ctx check
1 parent 6a40675 commit 147da5f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

peer/network.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ func NewNetwork(p2pNetwork *p2p.Network, appSender common.AppSender, codec codec
123123
// Returns the ID of the chosen peer, and an error if the request could not
124124
// be sent to a peer with the desired [minVersion].
125125
func (n *network) SendAppRequestAny(ctx context.Context, minVersion *version.Application, request []byte, handler message.ResponseHandler) (ids.NodeID, error) {
126+
// Propagate context errors immediately
127+
if err := ctx.Err(); err != nil {
128+
return ids.EmptyNodeID, err
129+
}
130+
126131
// Take a slot from total [activeAppRequests] and block until a slot becomes available.
127132
if err := n.activeAppRequests.Acquire(ctx, 1); err != nil {
128-
if errors.Is(err, context.Canceled) {
129-
return ids.EmptyNodeID, err
130-
}
131133
return ids.EmptyNodeID, errAcquiringSemaphore
132134
}
133135

0 commit comments

Comments
 (0)