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

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Tue Dec 20 17:23:10 UTC 2022



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


Commits:
dc7197be by Ben Gamari at 2022-12-20T12:23:03-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
=====================================
@@ -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/dc7197bef34f9fd70dc7ce03a1a2a238e7e6c6a9

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/dc7197bef34f9fd70dc7ce03a1a2a238e7e6c6a9
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/20221220/faaa996f/attachment-0001.html>


More information about the ghc-commits mailing list