This commit is contained in:
jdl committed 2024-12-24 19:41:07 +01:00
1 parent 6117a0afe4
commit b8d814f636
1 file changed
+3 -2
+3 -2
View File
@@ -5,7 +5,6 @@ import (
"log"
"net"
"net/netip"
"runtime/debug"
"sync"
)
@@ -21,9 +20,11 @@ func newConnWriter(conn *net.UDPConn) *connWriter {
}
func (w *connWriter) WriteTo(packet []byte, addr netip.AddrPort) {
// Even though a conn is safe for concurrent use, it turns out that a mutex
// in Go is more fair when there's contention. Without this lock, control
// packets may fail to be sent in a timely manner causing timeouts.
w.lock.Lock()
if _, err := w.conn.WriteToUDPAddrPort(packet, addr); err != nil {
debug.PrintStack()
log.Fatalf("Failed to write to UDP port: %v", err)
}
w.lock.Unlock()