Skip to content

Commit

Permalink
fix(router): router.chDesc concurrent map iteration and write in pque…
Browse files Browse the repository at this point in the history
…ue (#794)
  • Loading branch information
lklimek authored May 22, 2024
1 parent a1396fd commit 8dd12fd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/p2p/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func NewRouter(
return router, nil
}

// createQueueFactory creates a queue factory function based on the queue type
//
// Caller should hold the r.channelMtx RLock.
func (r *Router) createQueueFactory(ctx context.Context) (func(int) queue, error) {
switch r.options.QueueType {
case queueTypeFifo:
Expand All @@ -224,7 +227,6 @@ func (r *Router) createQueueFactory(ctx context.Context) (func(int) queue, error
if size%2 != 0 {
size++
}

q := newPQScheduler(r.logger, r.metrics, r.lc, r.chDescs, uint(size)/2, uint(size)/2, defaultCapacity)
q.start(ctx)
return q
Expand Down Expand Up @@ -601,7 +603,10 @@ func (r *Router) getOrMakeQueue(peerID types.NodeID, channels ChannelIDSet) queu
return peerQueue
}

r.channelMtx.RLock()
peerQueue := r.queueFactory(queueBufferDefault)
r.channelMtx.RUnlock()

r.peerQueues[peerID] = peerQueue
r.peerChannels[peerID] = channels
return peerQueue
Expand Down

0 comments on commit 8dd12fd

Please sign in to comment.