fix 6yhqpH81tK address-in-use-after-restart-macos

This commit is contained in:
voidlizard 2025-02-14 08:00:20 +03:00
parent 4ca064bec9
commit 52dff69f74
1 changed files with 5 additions and 1 deletions

View File

@ -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