Skip to content

Commit 036ad1f

Browse files
committed
use withMVar to prevent stm dead lock
1 parent e4fd853 commit 036ad1f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module Development.IDE.Core.Shake(
7575
VFSModified(..), getClientConfigAction,
7676
) where
7777

78-
import Control.Concurrent (takeMVar, withMVar)
78+
import Control.Concurrent (withMVar)
7979
import Control.Concurrent.Async
8080
import Control.Concurrent.STM
8181
import Control.Concurrent.STM.Stats (atomicallyNamed)
@@ -729,17 +729,16 @@ shakeSessionInit recorder ide@IdeState{..} = do
729729

730730
shakeShut :: Recorder (WithPriority Log) -> IdeState -> IO ()
731731
shakeShut recorder IdeState{..} = do
732-
res <- timeout 1 $ takeMVar shakeSession
732+
res <- timeout 1 $ withMVar shakeSession $ \runner -> do
733+
-- Shake gets unhappy if you try to close when there is a running
734+
-- request so we first abort that.
735+
cancelShakeSession runner
736+
void $ shakeDatabaseProfile shakeDb
737+
progressStop $ progress shakeExtras
738+
stopMonitoring
733739
case res of
734-
Just session -> do
735-
-- Shake gets unhappy if you try to close when there is a running
736-
-- request so we first abort that.
737-
cancelShakeSession session
738-
void $ shakeDatabaseProfile shakeDb
739-
progressStop $ progress shakeExtras
740-
stopMonitoring
741-
case res of
742740
Nothing -> logWith recorder Error $ LogTimeOutShuttingDownWaitForSessionVar 1
741+
Just _ -> pure ()
743742

744743

745744
-- | This is a variant of withMVar where the first argument is run unmasked and if it throws

0 commit comments

Comments
 (0)