Fix listener thread listening after the server process was stopped
authorLuke Lau <luke_lau@icloud.com>
Thu, 14 May 2020 20:18:13 +0000 (21:18 +0100)
committerLuke Lau <luke_lau@icloud.com>
Thu, 14 May 2020 20:18:13 +0000 (21:18 +0100)
Therefore fixes hGetLine: illegal operation (handle is closed)
exceptions, because the handles were being closed whilst the listener
thread was still reading from them.

Fixes #66

src/Language/Haskell/LSP/Test/Session.hs

index 56e206d8bc8d1681cc4b5b3440fdae1a9b1db1c3..9076a8e5e02e9ed819479a7d10c2f3a2d4ffc21a 100644 (file)
@@ -267,7 +267,9 @@ runSessionWithHandles serverIn serverOut serverProc serverHandler config caps ro
       serverAndListenerFinalizer tid = do
         finally (timeout (messageTimeout config * 1^6)
                          (runSession' exitServer))
-                (cleanupProcess server >> killThread tid)
+                -- Make sure to kill the listener first, before closing
+                -- handles etc via cleanupProcess
+                (killThread tid >> cleanupProcess server)
 
   (result, _) <- bracket serverListenerLauncher
                          serverAndListenerFinalizer