summaryrefslogtreecommitdiffhomepage
path: root/conn
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-02-10 00:43:31 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-10 00:43:31 +0100
commitaabc3770bad3ac6674a7a3952cdcd88f11dd1a72 (patch)
tree3497cdfa52129ff8657a9072364d476454efb0b0 /conn
parent484a9fd32494176526e0ffe81413e73362a6f92d (diff)
conn: close old fd before trying again
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conn')
-rw-r--r--conn/conn_default.go1
-rw-r--r--conn/conn_linux.go1
2 files changed, 2 insertions, 0 deletions
diff --git a/conn/conn_default.go b/conn/conn_default.go
index 2360068..82a1e42 100644
--- a/conn/conn_default.go
+++ b/conn/conn_default.go
@@ -99,6 +99,7 @@ again:
bind.ipv6, port, err = listenNet("udp6", port)
if uport == 0 && err != nil && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
+ bind.ipv4.Close()
tries++
goto again
}
diff --git a/conn/conn_linux.go b/conn/conn_linux.go
index 716028f..f07c3bb 100644
--- a/conn/conn_linux.go
+++ b/conn/conn_linux.go
@@ -123,6 +123,7 @@ again:
bind.sock4, newPort, err = create4(port)
if err != nil {
if originalPort == 0 && err == syscall.EADDRINUSE && tries < 100 {
+ unix.Close(bind.sock6)
tries++
goto again
}