Skip to content

Commit

Permalink
disconnect the peer only once
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Mar 21, 2024
1 parent 8c9a6ae commit 484c25d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libp2p/protocols/pubsub/pubsubpeer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type

rpcmessagequeue: RpcMessageQueue
maxNumElementInNonPriorityQueue*: int # The max number of elements allowed in the non-priority queue.
disconnected: bool

RPCHandler* = proc(peer: PubSubPeer, data: seq[byte]): Future[void]
{.gcsafe, raises: [].}
Expand Down Expand Up @@ -345,8 +346,12 @@ proc sendEncoded*(p: PubSubPeer, msg: seq[byte], isHighPriority: bool): Future[v
f
else:
if len(p.rpcmessagequeue.nonPriorityQueue) == p.maxNumElementInNonPriorityQueue:
libp2p_pubsub_disconnects_over_non_priority_queue_limit.inc()
p.closeSendConn(PubSubPeerEventKind.DisconnectionRequested)
if not p.disconnected:
p.disconnected = true
libp2p_pubsub_disconnects_over_non_priority_queue_limit.inc()
p.closeSendConn(PubSubPeerEventKind.DisconnectionRequested)
else:
Future[void].completed()
else:
let f = p.rpcmessagequeue.nonPriorityQueue.addLast(msg)
when defined(pubsubpeer_queue_metrics):
Expand Down

0 comments on commit 484c25d

Please sign in to comment.