Skip to content

Commit 01d8c30

Browse files
committed
intra/tunnel: serialize access to tunnel.Tunnel to avoid race
1 parent e467aad commit 01d8c30

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

intra/tunnel.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type Tunnel interface {
102102

103103
type rtunnel struct {
104104
tunnel.Tunnel
105+
tunmu sync.Mutex // serializes access to tunnel.Tunnel
105106
ctx context.Context
106107
done context.CancelFunc
107108
proxies ipn.Proxies
@@ -224,6 +225,9 @@ func (t *rtunnel) SetLinkAndRoutes(fd, mtu, engine int) error {
224225
return errClosed
225226
}
226227

228+
t.tunmu.Lock()
229+
defer t.tunmu.Unlock()
230+
227231
mtudiff := t.Tunnel.Mtu() != int32(mtu)
228232
l3 := settings.L3(engine)
229233
l3diff := dialers.IPProtos(l3)
@@ -303,7 +307,9 @@ func (t *rtunnel) Stat() (*x.NetStat, error) {
303307
}
304308

305309
func (t *rtunnel) stat() (*x.NetStat, error) {
310+
t.tunmu.Lock()
306311
out, err := t.Tunnel.Stat()
312+
t.tunmu.Unlock()
307313

308314
if err != nil {
309315
return nil, err

0 commit comments

Comments
 (0)