Skip to content

Commit

Permalink
peer/network: move ctx check
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Aug 23, 2024
1 parent 6a40675 commit 147da5f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions peer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ func NewNetwork(p2pNetwork *p2p.Network, appSender common.AppSender, codec codec
// Returns the ID of the chosen peer, and an error if the request could not
// be sent to a peer with the desired [minVersion].
func (n *network) SendAppRequestAny(ctx context.Context, minVersion *version.Application, request []byte, handler message.ResponseHandler) (ids.NodeID, error) {
// Propagate context errors immediately
if err := ctx.Err(); err != nil {
return ids.EmptyNodeID, err
}

// Take a slot from total [activeAppRequests] and block until a slot becomes available.
if err := n.activeAppRequests.Acquire(ctx, 1); err != nil {
if errors.Is(err, context.Canceled) {
return ids.EmptyNodeID, err
}
return ids.EmptyNodeID, errAcquiringSemaphore
}

Expand Down

0 comments on commit 147da5f

Please sign in to comment.