1
0
mirror of https://git.zx2c4.com/wireguard-go synced 2024-11-15 01:05:15 +01:00

conn: close old fd before trying again

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2021-02-10 00:43:31 +01:00
parent 484a9fd324
commit aabc3770ba
2 changed files with 2 additions and 0 deletions

View File

@ -99,6 +99,7 @@ again:
bind.ipv6, port, err = listenNet("udp6", port) bind.ipv6, port, err = listenNet("udp6", port)
if uport == 0 && err != nil && errors.Is(err, syscall.EADDRINUSE) && tries < 100 { if uport == 0 && err != nil && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
bind.ipv4.Close()
tries++ tries++
goto again goto again
} }

View File

@ -123,6 +123,7 @@ again:
bind.sock4, newPort, err = create4(port) bind.sock4, newPort, err = create4(port)
if err != nil { if err != nil {
if originalPort == 0 && err == syscall.EADDRINUSE && tries < 100 { if originalPort == 0 && err == syscall.EADDRINUSE && tries < 100 {
unix.Close(bind.sock6)
tries++ tries++
goto again goto again
} }