diff --git a/dial_sync.go b/dial_sync.go index edb6c898..50f3a698 100644 --- a/dial_sync.go +++ b/dial_sync.go @@ -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, @@ -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.