[Git][ghc/ghc][wip/setnumcapabilities] base: Fix event manager shutdown race on non-Linux platforms

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Wed Dec 21 20:42:16 UTC 2022



Ben Gamari pushed to branch wip/setnumcapabilities at Glasgow Haskell Compiler / GHC


Commits:
62e6c27f by Ben Gamari at 2022-12-21T15:41:54-05:00
base: Fix event manager shutdown race on non-Linux platforms

During shutdown it's possible that we will attempt to use a closed fd
to wakeup another capability's event manager. On the Linux eventfd path
we were careful to handle this. However on the non-Linux path we failed
to do so. Fix this.

- - - - -


1 changed file:

- libraries/base/GHC/Event/Control.hs


Changes:

=====================================
libraries/base/GHC/Event/Control.hs
=====================================
@@ -50,7 +50,7 @@ import System.Posix.Types (Fd)
 import Foreign.C.Error (throwErrnoIfMinus1, eBADF)
 import Foreign.C.Types (CULLong(..))
 #else
-import Foreign.C.Error (eAGAIN, eWOULDBLOCK)
+import Foreign.C.Error (eAGAIN, eWOULDBLOCK, eBADF)
 #endif
 
 data ControlMessage = CMsgWakeup
@@ -211,8 +211,15 @@ sendWakeup c = do
     _ | n /= -1   -> return ()
       | otherwise -> do
                    errno <- getErrno
-                   when (errno /= eAGAIN && errno /= eWOULDBLOCK) $
-                     throwErrno "sendWakeup"
+                   isDead <- readIORef (controlIsDead c)
+                   case () of
+                     _   -- Someone else has beat us to waking it up
+                       | errno == eAGAIN          -> return ()
+                       | errno == eWOULDBLOCK     -> return ()
+                         -- we are shutting down
+                       | errno == eBADF && isDead -> return ()
+                         -- something bad happened
+                       | otherwise                -> throwErrno "sendWakeup"
 #endif
 
 sendDie :: Control -> IO ()



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/62e6c27fb884ce7ffb8e0513516888d8a40900ed

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/62e6c27fb884ce7ffb8e0513516888d8a40900ed
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221221/fee89393/attachment-0001.html>


More information about the ghc-commits mailing list