- finally (timeout (messageTimeout config * 1^6)
- (runSession' exitServer))
- (cleanupProcess server >> killThread tid)
+ let cleanup
+ | 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))
+ -- Make sure to kill the listener first, before closing
+ -- handles etc via cleanupProcess
+ (killThread tid >> cleanup)