Skip to content

Commit a59656a

Browse files
committed
netstack: on swap, always stop dispatcher
1 parent 94dc310 commit a59656a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

intra/netstack/fdbased.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ func createInboundDispatcher(e *endpoint, fd int) (linkDispatcher, error) {
232232

233233
// Implements Swapper.
234234
func (e *endpoint) Swap(fd, mtu int) (err error) {
235+
var prev linkDispatcher
236+
defer func() {
237+
// TODO: should we let the previous dispatcher stop on EOF?
238+
if prev != nil && !settings.Debug {
239+
go prev.stop()
240+
}
241+
}()
242+
235243
if err = unix.SetNonblock(fd, true); err != nil {
236244
return fmt.Errorf("unix.SetNonblock(%v) failed: %v", fd, err)
237245
}
@@ -242,19 +250,14 @@ func (e *endpoint) Swap(fd, mtu int) (err error) {
242250

243251
e.Lock()
244252
defer e.Unlock()
245-
prev := e.inboundDispatcher
253+
prev = e.inboundDispatcher
246254

247255
e.inboundDispatcher, err = createInboundDispatcher(e, fd)
248256
if err != nil {
249257
return fmt.Errorf("createInboundDispatcher(...) = %v", err)
250258
}
251259
go e.dispatchLoop(e.inboundDispatcher)
252260

253-
// TODO: should we let the previous dispatcher stop on EOF?
254-
if prev != nil && !settings.Debug {
255-
go prev.stop()
256-
}
257-
258261
return nil
259262
}
260263

0 commit comments

Comments
 (0)