Skip to content

Commit 14a9b63

Browse files
authored
fix(p2p/protocols): fix rare data race in Peer.Handshake() ethereum#18951 (#2343)
1 parent a634215 commit 14a9b63

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

p2p/protocols/protocol.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,12 @@ func (p *Peer) handleIncoming(handle func(msg interface{}) error) error {
283283
// * the dialing peer needs to send the handshake first and then waits for remote
284284
// * the listening peer waits for the remote handshake and then sends it
285285
// returns the remote handshake and an error
286-
func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interface{}) error) (rhs interface{}, err error) {
286+
func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interface{}) error) (interface{}, error) {
287287
if _, ok := p.spec.GetCode(hs); !ok {
288288
return nil, errorf(ErrHandshake, "unknown handshake message type: %T", hs)
289289
}
290+
291+
var rhs interface{}
290292
errc := make(chan error, 2)
291293
handle := func(msg interface{}) error {
292294
rhs = msg
@@ -309,6 +311,7 @@ func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interf
309311
}()
310312

311313
for i := 0; i < 2; i++ {
314+
var err error
312315
select {
313316
case err = <-errc:
314317
case <-ctx.Done():

0 commit comments

Comments
 (0)