Skip to content

Commit 8d37e81

Browse files
committed
tunnel: def runid waiting on the endpoint
1 parent 9b4111f commit 8d37e81

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

intra/core/async.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ func Periodic(id string, pctx context.Context, d time.Duration, f func()) contex
225225
}
226226

227227
// SigFin runs f in a goroutine and returns a channel that is closed when f returns.
228-
func SigFin(f func()) <-chan struct{} {
228+
func SigFin(id string, f func()) <-chan struct{} {
229229
done := make(chan struct{})
230-
Go("take", func() {
230+
Go("sigfin."+id, func() {
231231
defer close(done)
232232
f()
233233
})

intra/netstack/fdbased.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) {
380380

381381
// IsAttached implements stack.LinkEndpoint.IsAttached.
382382
func (e *endpoint) IsAttached() bool {
383-
d, _ := e.getDispatcher()
383+
d, _ := e.getDispatchers()
384384
return d != nil
385385
}
386386

@@ -574,15 +574,15 @@ func (e *endpoint) SetMTU(mtu uint32) {
574574
e.mtu.Store(mtu)
575575
}
576576

577-
func (e *endpoint) getDispatcher() (stack.NetworkDispatcher, *fds) {
577+
func (e *endpoint) getDispatchers() (stack.NetworkDispatcher, *fds) {
578578
e.RLock()
579579
defer e.RUnlock()
580580
return e.dispatcher, e.fds.Load()
581581
}
582582

583583
// InjectInbound ingresses a netstack-inbound packet.
584584
func (e *endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
585-
d, fds := e.getDispatcher()
585+
d, fds := e.getDispatchers()
586586
fd := fds.tun()
587587
log.VV("ns: tun(%d): inject-inbound (from tun) %d", fd, protocol)
588588
if d != nil && pkt != nil {

tunnel/tunnel.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"fmt"
3030
"os"
3131
"path/filepath"
32+
"strconv"
3233
"sync"
3334
"sync/atomic"
3435
"syscall"
@@ -108,13 +109,14 @@ func (t *gtunnel) waitForEndpoint(ctx context.Context) {
108109
// wait a bit to let the endpoint settle
109110
time.Sleep(betweenChecks)
110111
start := time.Now()
112+
runid := "g." + strconv.Itoa(i)
111113

112114
select {
113115
case <-ctx.Done():
114116
t.Disconnect() // may already be disconnected
115117
log.D("tun: waiter: ctx done; #%d", i)
116118
return
117-
case <-core.SigFin(t.ep.Wait): // wait until endpoint closes
119+
case <-core.SigFin(runid, t.ep.Wait): // wait until endpoint closes
118120
log.D("tun: waiter: endpoint not running; #%d", i)
119121
}
120122

0 commit comments

Comments
 (0)