Unverified Commit 141af4b2 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #37 from libp2p/fix/handshake-cancelled

Fix: Connection Closed after handshake
parents 32417a40 d3cafc00
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"errors" "errors"
"net" "net"
"os" "os"
"sync"
ci "github.com/libp2p/go-libp2p-core/crypto" ci "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
...@@ -81,9 +82,19 @@ func (t *Transport) handshake( ...@@ -81,9 +82,19 @@ func (t *Transport) handshake(
tlsConn.Close() tlsConn.Close()
default: default:
} }
done := make(chan struct{}) 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) defer close(done)
wg.Add(1)
go func() { go func() {
defer wg.Done()
select { select {
case <-done: case <-done:
case <-ctx.Done(): case <-ctx.Done():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment