Skip to content

Commit d20087b

Browse files
committed
tunnel/tunnel: on context done skip Disconnect
Disconnect results in an unnecessary notification to the user, while context cancellation (done) is not triggered unless Disconnect has already happened
1 parent 591fd20 commit d20087b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

tunnel/tunnel.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (t *gtunnel) waitForEndpoint(ctx context.Context) {
119119
select {
120120
case <-ctx.Done():
121121
log.D("tun: waiter: ctx done; #%d", i)
122-
i = maxchecks // exit loop
122+
return
123123
case <-core.SigFin(t.ep.Wait): // wait until endpoint closes
124124
log.D("tun: waiter: endpoint not running; #%d", i)
125125
}
@@ -137,12 +137,11 @@ func (t *gtunnel) waitForEndpoint(ctx context.Context) {
137137
i++
138138
}
139139
}
140-
waitDone := core.FmtTimeAsPeriod(waitStart)
141140
if !t.closed.Load() {
142141
// the endpoint closed without a Disconnect, this may happen
143142
// in cases where a panic was recovered and endpoint was
144143
// closed without a t.ep.Swap or t.stack.Destroy
145-
log.U(fmt.Sprintf("Deactivated! Down after %s", waitDone))
144+
log.U(fmt.Sprintf("Deactivated! Down after %s", core.FmtTimeAsPeriod(waitStart)))
146145
// todo: disconnect parent tunnel
147146
t.Disconnect() // may already be disconnected
148147
}
@@ -228,6 +227,7 @@ func NewGTunnel(pctx context.Context, fd, mtu int, l3 string, hdl netstack.GConn
228227
defer done()
229228
t.waitForEndpoint(ctx)
230229
}()
230+
231231
return
232232
}
233233

0 commit comments

Comments
 (0)