From 4e4d1a39f6b980c7785cb8ed190461299484348c Mon Sep 17 00:00:00 2001 From: Owen Date: Sat, 17 Jan 2026 17:35:00 -0800 Subject: [PATCH] Try to close the socket first Former-commit-id: ed4775bd263085442907fbc3ff97db2a79c9769f --- olm/olm.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/olm/olm.go b/olm/olm.go index 26fc0e4..286db25 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -797,17 +797,19 @@ func (o *Olm) RebindSocket() error { return fmt.Errorf("shared bind is not initialized") } - // Get the current port so we can try to reuse it - currentPort := o.sharedBind.GetPort() + // Close the old socket first to release the port, then try to rebind to the same port + currentPort, err := o.sharedBind.CloseSocket() + if err != nil { + return fmt.Errorf("failed to close old socket: %w", err) + } - logger.Info("Rebinding UDP socket (current port: %d)", currentPort) + logger.Info("Rebinding UDP socket (released port: %d)", currentPort) // Create a new UDP socket var newConn *net.UDPConn var newPort uint16 - var err error - // First try to bind to the same port + // First try to bind to the same port (now available since we closed the old socket) localAddr := &net.UDPAddr{ Port: int(currentPort), IP: net.IPv4zero,