Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp-test: fromJust crash in sendRequest #330

Open
pepeiborra opened this issue May 8, 2021 · 1 comment
Open

lsp-test: fromJust crash in sendRequest #330

pepeiborra opened this issue May 8, 2021 · 1 comment
Labels
component: lsp-test Specific issues of lsp-test package type: bug

Comments

@pepeiborra
Copy link
Collaborator

My tests randomly crash with:

test-binary: Maybe.fromJust: Nothing
CallStack (from HasCallStack):
  error, called at libraries/base/Data/Maybe.hs:148:21 in base:Data.Maybe
  fromJust, called at src/Language/LSP/Test.hs:327:20 in lsp-test-0.14.0.0-26fxKpgpCT6HDpy4E8JMz7:Language.LSP.Test

                                          
### Error in:   Unit tests - Dirties generateTargets after file edit
Timed out waiting to receive a message from the server.
Cases: 1  Tried: 1  Errors: 1  Failures: 0

Could this be a concurrency issue? The code doesn't seem thread-safe:

idn <- curReqId <$> get
modify $ \c -> c { curReqId = idn+1 }
let id = IdInt idn
let mess = RequestMessage "2.0" id method params
-- Update the request map
reqMap <- requestMap <$> ask
liftIO $ modifyMVar_ reqMap $
\r -> return $ fromJust $ updateRequestMap r id method

@bosu
Copy link

bosu commented May 14, 2021

I am seeing this as curReqId conflict between SInitialize and SShutdown requests.

Both of them start with curReqId == 0 (SShutdown is being called from its own Session monad instance). Therefore there is a possibility that shutdown sees outstanding initialize request
on the shared requestMap MVar.

The following naive patch fixes this for me:

diff --git a/lsp-test/src/Language/LSP/Test.hs b/lsp-test/src/Language/LSP/Test.hs
index 46bb8e4..60484ca 100644
--- a/lsp-test/src/Language/LSP/Test.hs
+++ b/lsp-test/src/Language/LSP/Test.hs
@@ -232,7 +232,9 @@ runSessionWithHandles' serverProc serverIn serverOut config' caps rootDir ses
sio
   where
   -- | Asks the server to shutdown and exit politely
   exitServer :: Session ()
-  exitServer = request_ SShutdown Empty >> sendNotification SExit Empty
+  exitServer = do
+    modify $ \c -> c { curReqId = -1 }
+    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

@jneira jneira added component: lsp-test Specific issues of lsp-test package type: bug labels Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: lsp-test Specific issues of lsp-test package type: bug
Projects
None yet
Development

No branches or pull requests

3 participants