From ddfb5b32fc9350cd395b1571da6122a13eb01301 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 19 Mar 2021 12:36:04 -0700 Subject: [PATCH] fix: do not use the request context when dialing Otherwise, canceling one dial request will cancel all "joined" dial requests. --- dial_sync.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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.