Skip to content

Commit abf5538

Browse files
committed
take awasy the session in shutdown to prevent race condition
1 parent 84cf7a6 commit abf5538

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

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

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

78+
import Control.Concurrent (withMVar)
7879
import Control.Concurrent.Async
7980
import Control.Concurrent.STM
8081
import Control.Concurrent.STM.Stats (atomicallyNamed)
@@ -724,14 +725,14 @@ shakeSessionInit recorder ide@IdeState{..} = do
724725
logWith recorder Debug LogSessionInitialised
725726

726727
shakeShut :: IdeState -> IO ()
727-
shakeShut IdeState{..} = do
728-
runner <- tryReadMVar shakeSession
729-
-- Shake gets unhappy if you try to close when there is a running
730-
-- request so we first abort that.
731-
for_ runner cancelShakeSession
732-
void $ shakeDatabaseProfile shakeDb
733-
progressStop $ progress shakeExtras
734-
stopMonitoring
728+
shakeShut IdeState{..} =
729+
withMVar shakeSession $ \ runner -> do
730+
-- Shake gets unhappy if you try to close when there is a running
731+
-- request so we first abort that.
732+
cancelShakeSession runner
733+
void $ shakeDatabaseProfile shakeDb
734+
progressStop $ progress shakeExtras
735+
stopMonitoring
735736

736737

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

ghcide/src/Development/IDE/LSP/LanguageServer.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,10 @@ shutdownHandler :: Recorder (WithPriority Log) -> IO () -> LSP.Handlers (ServerM
262262
shutdownHandler recorder stopReactor = LSP.requestHandler SMethod_Shutdown $ \_ resp -> do
263263
(_, ide) <- ask
264264
liftIO $ logWith recorder Debug LogServerShutdownMessage
265-
-- we need to shut down the ide session before stopping the reactor
266-
-- since SessionIO depends on the reactor, we may hang if we stop the reactor first
267-
268-
-- flush out the Shake session to record a Shake profile if applicable
269-
liftIO $ shakeShut ide
270265
-- stop the reactor to free up the hiedb connection
271266
liftIO stopReactor
267+
-- flush out the Shake session to record a Shake profile if applicable
268+
liftIO $ shakeShut ide
272269
resp $ Right Null
273270

274271
exitHandler :: IO () -> LSP.Handlers (ServerM c)

0 commit comments

Comments
 (0)