Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 288e7d1

Browse files
authored
fix: Flake on TestReplica/TwentyConcurrent (coder#4842)
This could actually cause connections to intermittently fail too when a CPU is absolutely pegged. It just so happens that only our runners have been that slow! Fixes coder#4607.
1 parent a390b73 commit 288e7d1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tailnet/conn.go

+12
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,18 @@ func NewConn(options *Options) (*Conn, error) {
216216
server.sendNode()
217217
})
218218
wireguardEngine.SetNetInfoCallback(func(ni *tailcfg.NetInfo) {
219+
server.logger.Info(context.Background(), "netinfo callback", slog.F("netinfo", ni))
220+
// If the lastMutex is blocked, it's possible that
221+
// multiple NetInfo callbacks occur at the same time.
222+
//
223+
// We need to ensure only the latest is sent!
224+
asOf := time.Now()
219225
server.lastMutex.Lock()
226+
if asOf.Before(server.lastNetInfo) {
227+
server.lastMutex.Unlock()
228+
return
229+
}
230+
server.lastNetInfo = asOf
220231
server.lastPreferredDERP = ni.PreferredDERP
221232
server.lastDERPLatency = ni.DERPLatency
222233
server.lastMutex.Unlock()
@@ -269,6 +280,7 @@ type Conn struct {
269280
// It's only possible to store these values via status functions,
270281
// so the values must be stored for retrieval later on.
271282
lastStatus time.Time
283+
lastNetInfo time.Time
272284
lastEndpoints []string
273285
lastPreferredDERP int
274286
lastDERPLatency map[string]float64

0 commit comments

Comments
 (0)