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

Commit

Permalink
improve correctness of closing connections on failure
Browse files Browse the repository at this point in the history
may be related to ipfs/kubo#6197

(but I can't find one)
  • Loading branch information
Stebalien committed Apr 26, 2019
1 parent 773b63c commit 386affd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (u *Upgrader) upgrade(ctx context.Context, t transport.Transport, maconn ma
}
smconn, err := u.setupMuxer(ctx, sconn, p)
if err != nil {
conn.Close()
sconn.Close()
return nil, fmt.Errorf("failed to negotiate security stream multiplexer: %s", err)
}
return &transportConn{
Expand Down Expand Up @@ -122,6 +122,10 @@ func (u *Upgrader) setupMuxer(ctx context.Context, conn net.Conn, p peer.ID) (sm
case <-done:
return smconn, err
case <-ctx.Done():
// interrupt this process
conn.Close()
// wait for to finish
<-done
return nil, ctx.Err()
}
}

0 comments on commit 386affd

Please sign in to comment.