mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-14 15:07:55 +00:00
net/netcheck,wgengine/magicsock: align DERP frame receive time heuristics
The netcheck package and the magicksock package coordinate via the health package, but both sides have time based heuristics through indirect dependencies. These were misaligned, so the implemented heuristic aimed at reducing DERP moves while there is active traffic were non-operational about 3/5ths of the time. It is problematic to setup a good test for this integration presently, so instead I added comment breadcrumbs along with the initial fix. Updates #8603 Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:

committed by
James Tucker

parent
1fbaf26106
commit
6e334e64a1
@@ -35,6 +35,12 @@ import (
|
||||
"tailscale.com/util/testenv"
|
||||
)
|
||||
|
||||
// frameReceiveRecordRate is the minimum time between updates to last frame
|
||||
// received times.
|
||||
// Note: this is relevant to other parts of the system, such as netcheck
|
||||
// preferredDERPFrameTime, so update with care.
|
||||
const frameReceiveRecordRate = 5 * time.Second
|
||||
|
||||
// useDerpRoute reports whether magicsock should enable the DERP
|
||||
// return path optimization (Issue 150).
|
||||
//
|
||||
@@ -569,7 +575,7 @@ func (c *Conn) runDerpReader(ctx context.Context, derpFakeAddr netip.AddrPort, d
|
||||
bo.BackOff(ctx, nil) // reset
|
||||
|
||||
now := time.Now()
|
||||
if lastPacketTime.IsZero() || now.Sub(lastPacketTime) > 5*time.Second {
|
||||
if lastPacketTime.IsZero() || now.Sub(lastPacketTime) > frameReceiveRecordRate {
|
||||
health.NoteDERPRegionReceivedFrame(regionID)
|
||||
lastPacketTime = now
|
||||
}
|
||||
|
16
wgengine/magicsock/derp_test.go
Normal file
16
wgengine/magicsock/derp_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package magicsock
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"tailscale.com/net/netcheck"
|
||||
)
|
||||
|
||||
func CheckDERPHeuristicTimes(t *testing.T) {
|
||||
if netcheck.PreferredDERPFrameTime <= frameReceiveRecordRate {
|
||||
t.Errorf("PreferredDERPFrameTime too low; should be at least frameReceiveRecordRate")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user