From b8d814f636a09b7059199fde74a5e9fb6b827537 Mon Sep 17 00:00:00 2001 From: jdl Date: Tue, 24 Dec 2024 19:41:07 +0100 Subject: [PATCH] Cleanup --- node/conn.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/node/conn.go b/node/conn.go index 7671f36..b055ff8 100644 --- a/node/conn.go +++ b/node/conn.go @@ -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()