Skip to content

Commit 055747e

Browse files
marten-seemannMarcoPolo
authored andcommitted
quic: fix race condition when generating random holepunch packet (#2263)
1 parent c309692 commit 055747e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

p2p/transport/quic/transport.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ type transport struct {
4545

4646
holePunchingMx sync.Mutex
4747
holePunching map[holePunchKey]*activeHolePunch
48-
rnd rand.Rand
48+
49+
rndMx sync.Mutex
50+
rnd rand.Rand
4951

5052
connMx sync.Mutex
5153
conns map[quic.Connection]*conn
@@ -218,7 +220,10 @@ func (t *transport) holePunch(ctx context.Context, raddr ma.Multiaddr, p peer.ID
218220
var punchErr error
219221
loop:
220222
for i := 0; ; i++ {
221-
if _, err := t.rnd.Read(payload); err != nil {
223+
t.rndMx.Lock()
224+
_, err := t.rnd.Read(payload)
225+
t.rndMx.Unlock()
226+
if err != nil {
222227
punchErr = err
223228
break
224229
}

0 commit comments

Comments
 (0)