diff options
author | Ferenc Szabo <frncmx@gmail.com> | 2019-01-29 21:51:13 +0800 |
---|---|---|
committer | Anton Evangelatov <anton.evangelatov@gmail.com> | 2019-01-29 21:51:13 +0800 |
commit | a0ac3b6a1a1818285b74d9580c6d331837ec2e31 (patch) | |
tree | 43ebfff5740576e0aa848d5118de3b783c92ad2d /p2p/protocols | |
parent | e9daed189e237d023091006e298e4d7041d9f872 (diff) | |
download | go-tangerine-a0ac3b6a1a1818285b74d9580c6d331837ec2e31.tar go-tangerine-a0ac3b6a1a1818285b74d9580c6d331837ec2e31.tar.gz go-tangerine-a0ac3b6a1a1818285b74d9580c6d331837ec2e31.tar.bz2 go-tangerine-a0ac3b6a1a1818285b74d9580c6d331837ec2e31.tar.lz go-tangerine-a0ac3b6a1a1818285b74d9580c6d331837ec2e31.tar.xz go-tangerine-a0ac3b6a1a1818285b74d9580c6d331837ec2e31.tar.zst go-tangerine-a0ac3b6a1a1818285b74d9580c6d331837ec2e31.zip |
p2p/protocols: fix rare data race in Peer.Handshake() (#18951)
Diffstat (limited to 'p2p/protocols')
-rw-r--r-- | p2p/protocols/protocol.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/p2p/protocols/protocol.go b/p2p/protocols/protocol.go index bf879b985..1600a11f9 100644 --- a/p2p/protocols/protocol.go +++ b/p2p/protocols/protocol.go @@ -386,10 +386,12 @@ func (p *Peer) handleIncoming(handle func(ctx context.Context, msg interface{}) // * the dialing peer needs to send the handshake first and then waits for remote // * the listening peer waits for the remote handshake and then sends it // returns the remote handshake and an error -func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interface{}) error) (rhs interface{}, err error) { +func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interface{}) error) (interface{}, error) { if _, ok := p.spec.GetCode(hs); !ok { return nil, errorf(ErrHandshake, "unknown handshake message type: %T", hs) } + + var rhs interface{} errc := make(chan error, 2) handle := func(ctx context.Context, msg interface{}) error { rhs = msg @@ -412,6 +414,7 @@ func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interf }() for i := 0; i < 2; i++ { + var err error select { case err = <-errc: case <-ctx.Done(): |