Shutting down correct now

Former-commit-id: 692800b411
This commit is contained in:
Owen
2025-11-25 21:21:35 -05:00
parent a32e91de24
commit a38d1ef8a8
4 changed files with 53 additions and 22 deletions

View File

@@ -839,28 +839,24 @@ func Close() {
uapiListener = nil
}
// Close TUN device first to unblock any reads
logger.Debug("Closing TUN device")
if tdev != nil {
tdev.Close()
tdev = nil
}
// Close filtered device (this will close the closed channel and stop pump goroutine)
logger.Debug("Closing MiddleDevice")
if middleDev != nil {
middleDev.Close()
middleDev = nil
}
// Stop DNS proxy
// Stop DNS proxy first - it uses the middleDev for packet filtering
logger.Debug("Stopping DNS proxy")
if dnsProxy != nil {
dnsProxy.Stop()
dnsProxy = nil
}
// Now close WireGuard device
// Close MiddleDevice first - this closes the TUN and signals the closed channel
// This unblocks the pump goroutine and allows WireGuard's TUN reader to exit
logger.Debug("Closing MiddleDevice")
if middleDev != nil {
middleDev.Close()
middleDev = nil
}
// Note: tdev is closed by middleDev.Close() since middleDev wraps it
tdev = nil
// Now close WireGuard device - its TUN reader should have exited by now
logger.Debug("Closing WireGuard device")
if dev != nil {
dev.Close() // This will call sharedBind.Close() which releases WireGuard's reference