Skip to content

Commit a4cb23a

Browse files
committed
tun: fix race during WriteNotify and Close
Signed-off-by: Spike Curtis <[email protected]>
1 parent 03c5a0c commit a4cb23a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: tun/netstack/tun.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (tun *netTun) WriteNotify() {
166166
}
167167

168168
func (tun *netTun) Close() error {
169-
tun.stack.RemoveNIC(1)
169+
tun.stack.Destroy()
170170

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

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

0 commit comments

Comments
 (0)