Cleanup
This commit is contained in:
parent
6117a0afe4
commit
b8d814f636
@ -5,7 +5,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"runtime/debug"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,9 +20,11 @@ func newConnWriter(conn *net.UDPConn) *connWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *connWriter) WriteTo(packet []byte, addr netip.AddrPort) {
|
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()
|
w.lock.Lock()
|
||||||
if _, err := w.conn.WriteToUDPAddrPort(packet, addr); err != nil {
|
if _, err := w.conn.WriteToUDPAddrPort(packet, addr); err != nil {
|
||||||
debug.PrintStack()
|
|
||||||
log.Fatalf("Failed to write to UDP port: %v", err)
|
log.Fatalf("Failed to write to UDP port: %v", err)
|
||||||
}
|
}
|
||||||
w.lock.Unlock()
|
w.lock.Unlock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user