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

Commit

Permalink
fix: do not use the request context when dialing
Browse files Browse the repository at this point in the history
Otherwise, canceling one dial request will cancel all "joined" dial requests.
  • Loading branch information
Stebalien committed Mar 19, 2021
1 parent d73f313 commit 14d544b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dial_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ func (ad *activeDial) start(ctx context.Context) {
ad.cancel()
}

func (ds *DialSync) getActiveDial(ctx context.Context, p peer.ID) *activeDial {
func (ds *DialSync) getActiveDial(p peer.ID) *activeDial {
ds.dialsLk.Lock()
defer ds.dialsLk.Unlock()

actd, ok := ds.dials[p]
if !ok {
adctx, cancel := context.WithCancel(ctx)
// This code intentionally uses the background context. Otherwise, if the first call
// to Dial is canceled, subsequent dial calls will also be canceled.
// XXX: this also breaks direct connection logic. We will need to pipe the
// information through some other way.
adctx, cancel := context.WithCancel(context.Background())
actd = &activeDial{
id: p,
cancel: cancel,
Expand All @@ -123,7 +127,7 @@ func (ds *DialSync) getActiveDial(ctx context.Context, p peer.ID) *activeDial {
// DialLock initiates a dial to the given peer if there are none in progress
// then waits for the dial to that peer to complete.
func (ds *DialSync) DialLock(ctx context.Context, p peer.ID) (*Conn, error) {
return ds.getActiveDial(ctx, p).wait(ctx)
return ds.getActiveDial(p).wait(ctx)
}

// CancelDial cancels all in-progress dials to the given peer.
Expand Down

0 comments on commit 14d544b

Please sign in to comment.