File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -243,13 +243,16 @@ func (e *endpoint) Dispose() (err error) {
243243 log .W ("ns: tun: Dispose: no fds" )
244244 return nil
245245 }
246+
247+ e .Lock ()
248+ defer e .Unlock ()
249+
246250 prevfd := e .fds .Swap (invalidfd ) // prevfd may be invalidfd
247251 if prevfd == invalidfd {
248252 log .W ("ns: tun: Dispose: invalid prevfd" )
249253 return nil
250254 }
251- e .Lock ()
252- defer e .Unlock ()
255+
253256 if e .inboundDispatcher == nil {
254257 log .W ("ns: tun: Dispose: no inbound dispatcher" )
255258 // nothing to do
@@ -267,12 +270,12 @@ func (e *endpoint) Swap(fd int) (err error) {
267270 return fmt .Errorf ("ns: tun: set non blocking(%d) failed: %v" , fd , err )
268271 }
269272
270- prevfd := e .fds .Swap (fd ) // commence WritePackets() on fd
273+ e .Lock ()
274+ defer e .Unlock ()
271275
276+ prevfd := e .fds .Swap (fd ) // commence WritePackets() on fd
272277 log .D ("ns: swap: tun fd %d => %d" , prevfd , fd )
273278
274- e .Lock ()
275- defer e .Unlock ()
276279 if e .inboundDispatcher == nil { // prevfd must be 0 value if inbound is nil
277280 e .inboundDispatcher , err = createInboundDispatcher (e , fd )
278281 } else {
You can’t perform that action at this time.
0 commit comments