From 142e56bcbab23664fa866eb33708294ba6e949e8 Mon Sep 17 00:00:00 2001 From: soulomoon Date: Wed, 5 Nov 2025 16:56:59 +0800 Subject: [PATCH] Replace forkIO with async for server listener and update finalizer to cancel async --- lsp-test/src/Language/LSP/Test/Session.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lsp-test/src/Language/LSP/Test/Session.hs b/lsp-test/src/Language/LSP/Test/Session.hs index 70312011..15033169 100644 --- a/lsp-test/src/Language/LSP/Test/Session.hs +++ b/lsp-test/src/Language/LSP/Test/Session.hs @@ -83,6 +83,7 @@ import Data.IORef import Colog.Core (LogAction (..), WithSeverity (..), Severity (..)) import Data.String (fromString) import Data.Either (partitionEithers) +import Control.Concurrent.Async (async, cancel) -- | A session representing one instance of launching and connecting to a server. -- @@ -303,9 +304,9 @@ runSession' serverIn serverOut mServerProc serverHandler config caps rootDir exi errorHandler = throwTo mainThreadId :: SessionException -> IO () serverListenerLauncher = - forkIO $ catch (serverHandler serverOut context) errorHandler + async $ catch (serverHandler serverOut context) errorHandler msgTimeoutMs = messageTimeout config * 10^6 - serverAndListenerFinalizer tid = do + serverAndListenerFinalizer async = do let cleanup | Just sp <- mServerProc = do -- Give the server some time to exit cleanly @@ -318,7 +319,7 @@ runSession' serverIn serverOut mServerProc serverHandler config caps rootDir exi finally (timeout msgTimeoutMs (runSession' exitServer)) -- Make sure to kill the listener first, before closing -- handles etc via cleanupProcess - (killThread tid >> cleanup) + (cancel async >> cleanup) (result, _) <- bracket serverListenerLauncher serverAndListenerFinalizer