Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #51 from libp2p/fix/clear-cancelled-dials
Browse files Browse the repository at this point in the history
clear out extra dial jobs after dial finishes
  • Loading branch information
whyrusleeping authored Jan 4, 2018
2 parents 632ac48 + 2c697ba commit f7c26f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions swarm_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f7c26f4

Please sign in to comment.