Skip to content

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 cca3e39 + 0328485 commit 6b8d597
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions p2p/security/tls/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 6b8d597

Please sign in to comment.