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

Commit

Permalink
Merge pull request #37 from libp2p/fix/handshake-cancelled
Browse files Browse the repository at this point in the history
Fix: Connection Closed after handshake
  • Loading branch information
Stebalien authored Nov 1, 2019
2 parents 32417a4 + d3cafc0 commit 141af4b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"net"
"os"
"sync"

ci "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
Expand Down Expand Up @@ -81,9 +82,19 @@ func (t *Transport) handshake(
tlsConn.Close()
default:
}

done := make(chan struct{})
var wg sync.WaitGroup

// Ensure that we do not return before
// either being done or having a context
// cancellation.
defer wg.Wait()
defer close(done)

wg.Add(1)
go func() {
defer wg.Done()
select {
case <-done:
case <-ctx.Done():
Expand Down

0 comments on commit 141af4b

Please sign in to comment.