Skip to content

Commit 4b6e010

Browse files
committed
netstack: wrap up fd iff inbound dispatcher non-nil
1 parent 2fcbae9 commit 4b6e010

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

intra/netstack/fdbased.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ func (e *endpoint) Swap(fd int) (err error) {
274274
}
275275

276276
prevfd := e.fds.Swap(f) // commence WritePackets() on fd
277-
core.Go(
278-
"ns.swap.wrapup", func() { e.inboundDispatcher.wrapup(prevfd, wrapttl) },
279-
) // closes prevfd, which may be invalidfd
280277

281278
log.D("ns: tun: swap: fd %s => %d; err? %v", prevfd, fd, err)
282279

283280
if e.inboundDispatcher == nil { // prevfd must be 0 value if inbound is nil
281+
prevfd.stop() // prevfd may be invalid
284282
e.inboundDispatcher, err = createInboundDispatcher(e, f)
285283
} else {
284+
// closes prevfd, which may be invalidfd
285+
core.Go("ns.swap.wrapup", func() { e.inboundDispatcher.wrapup(prevfd, wrapttl) })
286286
e.inboundDispatcher.prepare(f)
287287
}
288288

0 commit comments

Comments
 (0)