Skip to content

Commit d912a49

Browse files
committed
net/tstun: add logging to aid developers missing Start calls
Since 5297bd2, 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 <[email protected]>
1 parent de5683f commit d912a49

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

net/tstun/wrap.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,23 @@ func (t *Wrapper) IdleDuration() time.Duration {
904904
return mono.Since(t.lastActivityAtomic.LoadAtomic())
905905
}
906906

907+
func (t *Wrapper) awaitStart() {
908+
for {
909+
select {
910+
case <-t.startCh:
911+
return
912+
case <-time.After(1 * time.Second):
913+
// Multiple times while remixing tailscaled I (Brad) have forgotten
914+
// to call Start and then wasted far too much time debugging.
915+
// I do not wish that debugging on anyone else. Hopefully this'll help:
916+
t.logf("tstun: awaiting Wrapper.Start call")
917+
}
918+
}
919+
}
920+
907921
func (t *Wrapper) Read(buffs [][]byte, sizes []int, offset int) (int, error) {
908922
if !t.started.Load() {
909-
<-t.startCh
923+
t.awaitStart()
910924
}
911925
// packet from OS read and sent to WG
912926
res, ok := <-t.vectorOutbound

0 commit comments

Comments
 (0)