net/tstun: add logging to aid developers missing Start calls

Since 5297bd2cff8ed03679, tstun.Wrapper has required its Start
method to be called for it to function. Failure to do so just
results in weird hangs and I've wasted too much time multiple
times now debugging. Hopefully this prevents more lost time.

Updates tailscale/corp#24454

Change-Id: I87f4539f7be7dc154627f8835a37a8db88c31be0
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2025-01-16 16:04:35 -08:00 committed by Brad Fitzpatrick
parent de5683f7c6
commit d912a49be6

View File

@ -904,9 +904,23 @@ func (t *Wrapper) IdleDuration() time.Duration {
return mono.Since(t.lastActivityAtomic.LoadAtomic())
}
func (t *Wrapper) awaitStart() {
for {
select {
case <-t.startCh:
return
case <-time.After(1 * time.Second):
// Multiple times while remixing tailscaled I (Brad) have forgotten
// to call Start and then wasted far too much time debugging.
// I do not wish that debugging on anyone else. Hopefully this'll help:
t.logf("tstun: awaiting Wrapper.Start call")
}
}
}
func (t *Wrapper) Read(buffs [][]byte, sizes []int, offset int) (int, error) {
if !t.started.Load() {
<-t.startCh
t.awaitStart()
}
// packet from OS read and sent to WG
res, ok := <-t.vectorOutbound