From 2c697bafcfd9053aba81e0878fcdcfe6b3f4e3c0 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 2 Jan 2018 21:09:00 -0800 Subject: [PATCH] clear out extra dial jobs after dial finishes --- limiter.go | 9 +++++++++ swarm_dial.go | 2 ++ 2 files changed, 11 insertions(+) diff --git a/limiter.go b/limiter.go index f6cf6dda..c3d89518 100644 --- a/limiter.go +++ b/limiter.go @@ -144,6 +144,15 @@ func (dl *dialLimiter) AddDialJob(dj *dialJob) { go dl.executeDial(dj) } +func (dl *dialLimiter) clearAllPeerDials(p peer.ID) { + dl.rllock.Lock() + defer dl.rllock.Unlock() + delete(dl.waitingOnPeerLimit, p) + // NB: the waitingOnFd list doesnt need to be cleaned out here, we will + // remove them as we encounter them because they are 'cancelled' at this + // point +} + // executeDial calls the dialFunc, and reports the result through the response // channel when finished. Once the response is sent it also releases all tokens // it held during the dial. diff --git a/swarm_dial.go b/swarm_dial.go index 1cc03580..1531bb2e 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -293,6 +293,8 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma. defaultDialFail := fmt.Errorf("failed to dial %s (default failure)", p) exitErr := defaultDialFail + defer s.limiter.clearAllPeerDials(p) + var active int for { select {