From 52dff69f742736a48e9c980cc1599627dac2bef7 Mon Sep 17 00:00:00 2001 From: voidlizard Date: Fri, 14 Feb 2025 08:00:20 +0300 Subject: [PATCH] fix 6yhqpH81tK address-in-use-after-restart-macos --- hbs2-core/lib/HBS2/Net/Messaging/UDP.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hbs2-core/lib/HBS2/Net/Messaging/UDP.hs b/hbs2-core/lib/HBS2/Net/Messaging/UDP.hs index 60384d99..fa54bbfe 100644 --- a/hbs2-core/lib/HBS2/Net/Messaging/UDP.hs +++ b/hbs2-core/lib/HBS2/Net/Messaging/UDP.hs @@ -66,6 +66,8 @@ newMessagingUDP reuse saddr = let a = addrAddress l so <- liftIO $ socket (addrFamily l) (addrSocketType l) (addrProtocol l) + liftIO $ withFdSocket so setCloseOnExecIfNeeded + when reuse $ do liftIO $ setSocketOption so ReuseAddr 1 @@ -102,7 +104,9 @@ runMessagingUDP MessagingUDP{..} = void $ flip runContT pure do so <- liftIO (readTVarIO sock) >>= orThrowUser "UDP socket is not ready" void $ ContT $ bracket (pure (Just so)) $ \case - Just so -> liftIO (close so >> atomically (writeTVar sock Nothing)) + Just so -> liftIO do + close so >> atomically (writeTVar sock Nothing) + Nothing -> pure () unless mcast $ do