WireGuard: Improve config error handling; Prevent panic in case of errors during server initialization (#4566)

https://github.com/XTLS/Xray-core/pull/4566#issuecomment-2764779273
This commit is contained in:
Ilya Gulya
2025-03-31 03:50:25 +05:00
committed by RPRX
parent 52a2c63682
commit 17207fc5e4
4 changed files with 83 additions and 28 deletions
+6 -7
View File
@@ -10,6 +10,7 @@ import (
"fmt"
"net/netip"
"os"
"sync"
"syscall"
"golang.zx2c4.com/wireguard/tun"
@@ -33,6 +34,7 @@ type netTun struct {
incomingPacket chan *buffer.View
mtu int
hasV4, hasV6 bool
closeOnce sync.Once
}
type Net netTun
@@ -174,18 +176,15 @@ func (tun *netTun) Flush() error {
// Close implements tun.Device
func (tun *netTun) Close() error {
tun.stack.RemoveNIC(1)
tun.closeOnce.Do(func() {
tun.stack.RemoveNIC(1)
if tun.events != nil {
close(tun.events)
}
tun.ep.Close()
tun.ep.Close()
if tun.incomingPacket != nil {
close(tun.incomingPacket)
}
})
return nil
}