Skip to content

Commit

Permalink
quic: fix race condition when generating random holepunch packet (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored and MarcoPolo committed May 4, 2023
1 parent c309692 commit 055747e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions p2p/transport/quic/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ type transport struct {

holePunchingMx sync.Mutex
holePunching map[holePunchKey]*activeHolePunch
rnd rand.Rand

rndMx sync.Mutex
rnd rand.Rand

connMx sync.Mutex
conns map[quic.Connection]*conn
Expand Down Expand Up @@ -218,7 +220,10 @@ func (t *transport) holePunch(ctx context.Context, raddr ma.Multiaddr, p peer.ID
var punchErr error
loop:
for i := 0; ; i++ {
if _, err := t.rnd.Read(payload); err != nil {
t.rndMx.Lock()
_, err := t.rnd.Read(payload)
t.rndMx.Unlock()
if err != nil {
punchErr = err
break
}
Expand Down

0 comments on commit 055747e

Please sign in to comment.