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

Since 5297bd2cff, 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>
pull/14676/head
Brad Fitzpatrick 11 months ago committed by Brad Fitzpatrick
parent de5683f7c6
commit d912a49be6

@ -904,9 +904,23 @@ func (t *Wrapper) IdleDuration() time.Duration {
return mono.Since(t.lastActivityAtomic.LoadAtomic()) 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) { func (t *Wrapper) Read(buffs [][]byte, sizes []int, offset int) (int, error) {
if !t.started.Load() { if !t.started.Load() {
<-t.startCh t.awaitStart()
} }
// packet from OS read and sent to WG // packet from OS read and sent to WG
res, ok := <-t.vectorOutbound res, ok := <-t.vectorOutbound

Loading…
Cancel
Save