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

Commit 141af4b

Browse files
authored
Merge pull request #37 from libp2p/fix/handshake-cancelled
Fix: Connection Closed after handshake
2 parents 32417a4 + d3cafc0 commit 141af4b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

transport.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"net"
88
"os"
9+
"sync"
910

1011
ci "github.com/libp2p/go-libp2p-core/crypto"
1112
"github.com/libp2p/go-libp2p-core/peer"
@@ -81,9 +82,19 @@ func (t *Transport) handshake(
8182
tlsConn.Close()
8283
default:
8384
}
85+
8486
done := make(chan struct{})
87+
var wg sync.WaitGroup
88+
89+
// Ensure that we do not return before
90+
// either being done or having a context
91+
// cancellation.
92+
defer wg.Wait()
8593
defer close(done)
94+
95+
wg.Add(1)
8696
go func() {
97+
defer wg.Done()
8798
select {
8899
case <-done:
89100
case <-ctx.Done():

0 commit comments

Comments
 (0)