From 467b5b4f0cbfca31ececce9dfd1e649df87067e8 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 20 Mar 2024 11:54:32 +0100 Subject: [PATCH] avoid cancelling send future (#1075) --- libp2p/protocols/pubsub/pubsubpeer.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index 1de6ea79e7..ed9dbb77c5 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -431,7 +431,9 @@ proc sendNonPriorityTask(p: PubSubPeer) {.async.} = # clearSendPriorityQueue ensures we're not waiting for an already-finished # future if p.rpcmessagequeue.sendPriorityQueue.len > 0: - await p.rpcmessagequeue.sendPriorityQueue[^1] + # `race` prevents `p.rpcmessagequeue.sendPriorityQueue[^1]` from being + # cancelled when this task is cancelled + discard await race(p.rpcmessagequeue.sendPriorityQueue[^1]) when defined(pubsubpeer_queue_metrics): libp2p_gossipsub_non_priority_queue_size.dec(labelValues = [$p.peerId]) await p.sendMsg(msg)