Skip to content

Commit 994f58c

Browse files
committed
netstack: unconditionally stop prevfd on Dispose
Even when inbound dispatcher isn't set up
1 parent 67be2a4 commit 994f58c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

intra/netstack/fdbased.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,14 @@ func (e *endpoint) Dispose() (err error) {
301301
defer e.Unlock()
302302

303303
prevfd := e.fds.Swap(invalidFds) // prevfd may be invalidfd
304-
if !prevfd.ok() {
305-
log.W("ns: tun: Dispose: invalid prevfd")
306-
return nil
307-
}
308304

309305
if e.inboundDispatcher == nil {
310-
log.W("ns: tun: Dispose: no inbound dispatcher")
306+
prevfd.stop() // prevfd may be invalidfd
307+
log.W("ns: tun: Dispose: %d; no inbound dispatcher", prevfd.tun())
311308
// nothing to do
312309
return nil
313310
}
311+
314312
// e.inboundDispatcher.prepare() will not close prevfd
315313
// dispatchLoop() will auto-exit on invalidfd
316314
core.Go("ns.dispose.wrapup", func() { e.inboundDispatcher.wrapup(prevfd, wrapttl) })
@@ -398,6 +396,9 @@ func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) {
398396
var err error
399397
e.inboundDispatcher, err = createInboundDispatcher(e, fds)
400398
logeif(err)("ns: tun(%d): attach: just-in-time createInboundDispatcher; err? %v", fd, err)
399+
if e.inboundDispatcher != nil {
400+
e.inboundDispatcher.prepare(fds)
401+
}
401402
rx = e.inboundDispatcher
402403
}
403404
go dispatchLoop(rx, fds, &e.wg)

0 commit comments

Comments
 (0)