Skip to content

Commit bea1f82

Browse files
committed
Wait for the server to exit cleanly
Fixes #70
1 parent fc3b353 commit bea1f82

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lsp-test/src/Language/Haskell/LSP/Test/Session.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import Language.Haskell.LSP.Test.Exceptions
7171
import System.Console.ANSI
7272
import System.Directory
7373
import System.IO
74-
import System.Process (ProcessHandle())
74+
import System.Process (waitForProcess, ProcessHandle())
7575
import System.Timeout
7676

7777
-- | A session representing one instance of launching and connecting to a server.
@@ -264,12 +264,15 @@ runSessionWithHandles serverIn serverOut serverProc serverHandler config caps ro
264264
serverListenerLauncher =
265265
forkIO $ catch (serverHandler serverOut context) errorHandler
266266
server = (Just serverIn, Just serverOut, Nothing, serverProc)
267+
msgTimeoutMs = messageTimeout config * 10^6
267268
serverAndListenerFinalizer tid = do
268-
finally (timeout (messageTimeout config * 1^6)
269-
(runSession' exitServer))
270-
-- Make sure to kill the listener first, before closing
271-
-- handles etc via cleanupProcess
272-
(killThread tid >> cleanupProcess server)
269+
finally (timeout msgTimeoutMs (runSession' exitServer)) $ do
270+
-- Make sure to kill the listener first, before closing
271+
-- handles etc via cleanupProcess
272+
killThread tid
273+
-- Give the server some time to exit cleanly
274+
timeout msgTimeoutMs (waitForProcess serverProc)
275+
cleanupProcess server
273276

274277
(result, _) <- bracket serverListenerLauncher
275278
serverAndListenerFinalizer

0 commit comments

Comments
 (0)