Skip to content

Commit

Permalink
tun: fix race during WriteNotify and Close
Browse files Browse the repository at this point in the history
Signed-off-by: Spike Curtis <[email protected]>
  • Loading branch information
spikecurtis committed May 2, 2024
1 parent 03c5a0c commit a4cb23a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tun/netstack/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (tun *netTun) WriteNotify() {
}

func (tun *netTun) Close() error {
tun.stack.RemoveNIC(1)
tun.stack.Destroy()

if tun.events != nil {
close(tun.events)
Expand All @@ -175,6 +175,8 @@ func (tun *netTun) Close() error {
tun.ep.Close()

if tun.incomingPacket != nil {
// It's safe to close the channel here because tun.stack.Destroy() ensures that no worker
// goroutines could be calling WriteNotify()
close(tun.incomingPacket)
}

Expand Down

0 comments on commit a4cb23a

Please sign in to comment.