where
-- | Asks the server to shutdown and exit politely
exitServer :: Session ()
- exitServer = request_ SShutdown (Nothing :: Maybe Value) >> sendNotification SExit Empty
+ exitServer = request_ SShutdown Empty >> sendNotification SExit Empty
-- | Listens to the server output until the shutdown ack,
-- makes sure it matches the record and signals any semaphores
errorHandler = throwTo mainThreadId :: SessionException -> IO ()
serverListenerLauncher =
forkIO $ catch (serverHandler serverOut context) errorHandler
- server = (Just serverIn, Just serverOut, Nothing, serverProc)
msgTimeoutMs = messageTimeout config * 10^6
serverAndListenerFinalizer tid = do
let cleanup
- | Just sp <- mServerProc = cleanupProcess (Just serverIn, Just serverOut, Nothing, sp)
+ | Just sp <- mServerProc = do
+ -- Give the server some time to exit cleanly
+ timeout msgTimeoutMs (waitForProcess sp)
+ cleanupProcess (Just serverIn, Just serverOut, Nothing, sp)
| otherwise = pure ()
- finally (timeout msgTimeoutMs (runSession' exitServer)) $ do
+ finally (timeout msgTimeoutMs (runSession' exitServer))
-- Make sure to kill the listener first, before closing
-- handles etc via cleanupProcess
- killThread tid
- -- Give the server some time to exit cleanly
-#ifndef mingw32_HOST_OS
- timeout msgTimeoutMs (waitForProcess serverProc)
-#endif
- cleanup
+ (killThread tid >> cleanup)
(result, _) <- bracket serverListenerLauncher
serverAndListenerFinalizer