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

'connection to server' error when start of vscode #676

Closed
Akopov4 opened this issue Jan 27, 2025 · 19 comments · Fixed by astral-sh/ruff#16262
Closed

'connection to server' error when start of vscode #676

Akopov4 opened this issue Jan 27, 2025 · 19 comments · Fixed by astral-sh/ruff#16262
Labels
bug Something isn't working

Comments

@Akopov4
Copy link

Akopov4 commented Jan 27, 2025

Type: Bug

On start of vscode i see connection error. See attached logs.

Extension version: 2025.4.0
VS Code version: Code 1.96.4 (cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba, 2025-01-16T00:16:19.038Z)
OS version: Linux x64 6.8.0-51-generic
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz (4 x 2828)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off
Load (avg) 2, 2, 2
Memory (System) 11.56GB (3.76GB free)
Process Argv --crash-reporter-id 758cea54-b332-4947-8de8-2cca64713a9f
Screen Reader no
VM 0%
DESKTOP_SESSION cinnamon
XDG_CURRENT_DESKTOP X-Cinnamon
XDG_SESSION_DESKTOP cinnamon
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
dvdeprecation:31068756
dwnewjupytercf:31046870
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc1:31192215
cf971741:31144450
iacca1:31171482
notype1cf:31157160
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
dwoutputs:31217127
hdaa2157:31222309
copilot_t_ci:31222730

Logs

Logs
0.004548381s  INFO main ruff_server::session::index: Registering workspace: /home/akop/Desktop/python
 0.010150689s  INFO ruff:main ruff_server::server: Configuration file watcher successfully registered
27.198583720s  WARN ruff:main ruff_server::server::api: Received notification $/setTrace which does not have a handler.
181.513263111s  WARN ruff:main ruff_server::server::api: Received notification $/setTrace which does not have a handler.
223.431877214s  INFO ruff:main ruff_server::server::connection: Shutdown request received. Waiting for an exit notification...
223.436303083s  INFO ruff:main ruff_server::server::connection: Exit notification received. Server shutting down...
 0.000055705s DEBUG main ruff_server::session::index::ruff_settings: Indexing settings for workspace: /home/akop/Desktop/python
 0.007230129s DEBUG ThreadId(06) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/akop/Desktop/python/.vscode
 0.007970978s DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/akop/Desktop/python/.venv
 0.009128272s  INFO main ruff_server::session::index: Registering workspace: /home/akop/Desktop/python
 0.012775332s  INFO ruff:main ruff_server::server: Configuration file watcher successfully registered
25.726426225s TRACE ruff:main notification{method="textDocument/didOpen"}: ruff_server::server::api: enter
25.900833360s TRACE ruff:worker:0 request{id=1 method="textDocument/diagnostic"}: ruff_server::server::api: enter
25.900921614s DEBUG ruff:worker:0 request{id=1 method="textDocument/diagnostic"}: ruff_server::resolve: Included path via `include`: /home/akop/Desktop/python/arrays/dynamic_array.py
25.908019752s TRACE ruff:worker:1 request{id=2 method="textDocument/codeAction"}: ruff_server::server::api: enter
27.771396245s TRACE ruff:worker:3 request{id=3 method="textDocument/hover"}: ruff_server::server::api: enter
30.792339207s TRACE ruff:worker:2 request{id=4 method="textDocument/codeAction"}: ruff_server::server::api: enter
34.918350091s TRACE ruff:worker:1 request{id=5 method="textDocument/codeAction"}: ruff_server::server::api: enter
51.336775760s TRACE ruff:worker:0 request{id=6 method="textDocument/codeAction"}: ruff_server::server::api: enter
53.193570583s TRACE ruff:worker:3 request{id=7 method="textDocument/codeAction"}: ruff_server::server::api: enter
57.213495697s  INFO     ruff:main ruff_server::server::connection: Shutdown request received. Waiting for an exit notification...
57.267534297s  INFO     ruff:main ruff_server::server::connection: Exit notification received. Server shutting down...
 0.000028836s DEBUG main ruff_server::session::index::ruff_settings: Indexing settings for workspace: /home/akop/Desktop/python
 0.019176416s DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/akop/Desktop/python/.mypy_cache
 0.019324133s DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/akop/Desktop/python/.venv
 0.020825004s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /home/akop/Desktop/python/.vscode
 0.040994454s  INFO main ruff_server::session::index: Registering workspace: /home/akop/Desktop/python
 0.053354356s TRACE ruff:main notification{method="textDocument/didOpen"}: ruff_server::server::api: enter
 0.071110621s TRACE ruff:main notification{method="$/cancelRequest"}: ruff_server::server::api: enter
 0.071578798s TRACE ruff:worker:0 request{id=1 method="textDocument/diagnostic"}: ruff_server::server::api: enter
 0.071693040s DEBUG ruff:worker:0 request{id=1 method="textDocument/diagnostic"}: ruff_server::resolve: Included path via `include`: /home/akop/Desktop/python/arrays/dynamic_array.py
 0.073010145s  INFO     ruff:main ruff_server::server::connection: Shutdown request received. Waiting for an exit notification...
ruff failed
Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification
[Error - 1:09:46 AM] Connection to server got closed. Server will not be restarted.
[Error - 1:09:46 AM] Stopping server failed
Message: Pending response rejected since connection got disposed
Code: -32097 

Ruff_Language Server_Trace.txt

@Akopov4 Akopov4 changed the title connection to server is closed error connection to server error when start of vscode Jan 27, 2025
@Akopov4 Akopov4 changed the title connection to server error when start of vscode 'connection to server' error when start of vscode Jan 27, 2025
@dhruvmanila
Copy link
Member

Sorry that you're unable to use the extension.

Can you provide more details to help debug the issue?

  • What are the VS Code settings for Ruff and Python?
  • Does it occur everytime you're opening the editor?
  • Does it occur only on this specific project or does it occur on all projects?

Thanks for providing the trace logs but that doesn't seem to match what I'm seeing in the server logs. For example, I see that there's a textDocument/didOpen notification but I don't see the corresponding entry in the trace logs. Can you verify that the trace logs are from the same session as the server logs?

I'm also curious to know what are those "A/B experiments"?

@Akopov4
Copy link
Author

Akopov4 commented Jan 29, 2025

No problem. It happens just after installation of extension. With default settings. I use python 3.12. A/B experiments were added by internal tool of vscode ide which generates bug reports. Yes, logs are for the same session. The defect persists every time I start ide, or restart server.

@dhruvmanila dhruvmanila added the needs-mre Needs more information for reproduction label Jan 30, 2025
@dhruvmanila
Copy link
Member

Yes, logs are for the same session.

That's interesting because the server logs and the trace logs does not match. For example, the textDocument/didOpen request as:

 0.040994454s  INFO main ruff_server::session::index: Registering workspace: /home/akop/Desktop/python
 0.053354356s TRACE ruff:main notification{method="textDocument/didOpen"}: ruff_server::server::api: enter

has no corresponding entry in the trace logs, ideally there should be. Does you VS Code settings look like this?

{
	"ruff.logLevel": "trace",
	"ruff.trace.server": "verbose"
}

@Akopov4
Copy link
Author

Akopov4 commented Jan 30, 2025

@dhruvmanila Yes. My settings are:

{ "ruff.logLevel": "trace", "ruff.trace.server": "verbose" }

Hmm, ... to be able to fix this error, i put

"ruff.nativeServer": "off",

Today, i tried to reproduce error and to get logs one more time . I have put
"ruff.nativeServer": "auto",

And error is no longer reproducible, strange behavior ....

@Akopov4
Copy link
Author

Akopov4 commented Jan 30, 2025

@dhruvmanila I have found the root cause of the problem.
one of the possible values of "ruff.nativeServer": is "on" . But if to set this parameter "on" - problem start occur again

@dhruvmanila
Copy link
Member

@dhruvmanila I have found the root cause of the problem. one of the possible values of "ruff.nativeServer": is "on" . But if to set this parameter "on" - problem start occur again

Hmm, that's worrying as it shouldn't cause any failure.

That's interesting because the server logs and the trace logs does not match. For example, the textDocument/didOpen request as:

 0.040994454s  INFO main ruff_server::session::index: Registering workspace: /home/akop/Desktop/python
 0.053354356s TRACE ruff:main notification{method="textDocument/didOpen"}: ruff_server::server::api: enter

has no corresponding entry in the trace logs, ideally there should be.

I think it would be useful to make sure that the logs are correct. What's the version of the Ruff that you're running? Can you try using the bundled Ruff executable by setting ruff.importStrategy: "useBundled" and see if the error persists?

@Akopov4
Copy link
Author

Akopov4 commented Jan 30, 2025

@dhruvmanila I use 2025.4.0. I have put

"ruff.importStrategy: "useBundled"

but it didn't help - problem still persists.
I have attached new logs

Ruff_language_server.txt
Ruff_Language Server_Trace.txt

@DingXuefeng
Copy link

same problem here.

  0.017332756s DEBUG ruff:worker:3 request{id=2 method="textDocument/diagnostic"}: ruff_server::resolve: Included path via `include`: /datafs/users/dingxf/neutrino-physics/water-phase-analysis/b8-analysis/RUN/massive/tool/single_job.py
   0.017348027s DEBUG ruff:worker:1 request{id=3 method="textDocument/diagnostic"}: ruff_server::resolve: Included path via `include`: /datafs/users/dingxf/neutrino-physics/water-phase-analysis/b8-analysis/tests/test_RUN/test_integration_single_job.py
   0.017735621s TRACE     ruff:main notification{method="notebookDocument/didOpen"}: ruff_server::server::api: enter
   0.017871466s DEBUG     ruff:main notification{method="notebookDocument/didOpen"}: ruff_server::resolve: Included path via `include`: /datafs/users/dingxf/neutrino-physics/water-phase-analysis/b8-analysis/RUN/analyze_new.ipynb
   0.019184458s TRACE     ruff:main notification{method="$/cancelRequest"}: ruff_server::server::api: enter
   0.019292087s TRACE     ruff:main notification{method="$/cancelRequest"}: ruff_server::server::api: enter
   0.019299175s TRACE     ruff:main notification{method="$/cancelRequest"}: ruff_server::server::api: enter
   0.019314306s  INFO     ruff:main ruff_server::server::connection: Shutdown request received. Waiting for an exit notification...
ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification
   0.000020825s DEBUG main ruff_server::session::index::ruff_settings: Indexing settings for workspace: /datafs/users/dingxf/neutrino-physics/water-phase-analysis/b8-analysis

@DingXuefeng
Copy link

@dhruvmanila I have found the root cause of the problem. one of the possible values of "ruff.nativeServer": is "on" . But if to set this parameter "on" - problem start occur again

I also observed this. I turn it off temporarily waiting for the developers to fix it. I also mentioned this at astral-sh/ruff#15991

@dhruvmanila
Copy link
Member

@DingXuefeng Are you able to reproduce this every time on any project that you open VS Code in? In your case, I'm wondering if it has got to do anything with request cancellation. The native server does not support cancellation but it seems that we send a default response to the request instead of ignoring it. I'm not sure how does a client consider that response.

https://github.com/astral-sh/ruff/blob/b6b1947010052b1987b585dd5d6d94173a246d57/crates/ruff_server/src/server/api/notifications/cancel.rs#L13-L23

@Martin-Milbradt
Copy link

Happens for me as well, but only in WSL, not Windows proper.

@dhruvmanila
Copy link
Member

@Martin-Milbradt Are you able to reproduce this consistently? Can you provide more details to help us narrow down the issue by providing us extension and server logs?

@Martin-Milbradt
Copy link

Martin-Milbradt commented Feb 19, 2025

Extension looks fine:

2025-02-19 15:40:32.910 [info] Using environment executable: /home/milli/.cargo/bin/ruff
2025-02-19 15:40:32.940 [info] Resolved 'ruff.nativeServer: auto' to use the native server
2025-02-19 15:40:32.941 [info] Found Ruff 0.7.4 at /home/milli/.cargo/bin/ruff
2025-02-19 15:40:32.941 [info] Server run command: /home/milli/.cargo/bin/ruff server
2025-02-19 15:40:32.941 [info] Server: Start requested.

Language Server errors out:

[Error - 2:55:07 PM] Stopping server failed
Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:161:15)
    at writeGeneric (node:internal/stream_base_commons:152:3)
    at Socket._writeGeneric (node:net:958:11)
    at Socket._write (node:net:970:8)
    at writeOrBuffer (node:internal/streams/writable:572:12)
    at _write (node:internal/streams/writable:501:10)
    at Socket.write (node:internal/streams/writable:510:10)
    at /home/milli/.vscode-server/extensions/charliermarsh.ruff-2025.8.0/dist/webpack:/ruff/node_modules/vscode-jsonrpc/lib/node/ril.js:88:29
    at new Promise (<anonymous>)
    at a.write (/home/milli/.vscode-server/extensions/charliermarsh.ruff-2025.8.0/dist/webpack:/ruff/node_modules/vscode-jsonrpc/lib/node/ril.js:78:16)
    at y.doWrite (/home/milli/.vscode-server/extensions/charliermarsh.ruff-2025.8.0/dist/webpack:/ruff/node_modules/vscode-jsonrpc/lib/common/messageWriter.js:99:33)
    at /home/milli/.vscode-server/extensions/charliermarsh.ruff-2025.8.0/dist/webpack:/ruff/node_modules/vscode-jsonrpc/lib/common/messageWriter.js:90:29
    at runNextTicks (node:internal/process/task_queues:60:5)
    at processImmediate (node:internal/timers:454:9)
ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification

The Language Server also has issues in Windows proper, but they don't get propagated to the top level (didn't notice them until checking out the log) and they don't seem to impact behavior.

ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification
panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\lsp-server-0.7.6\src\stdio.rs:28:37:
receiver was dropped, failed to send a message: "SendError(..)"
panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\lsp-server-0.7.6\src\stdio.rs:28:37:
receiver was dropped, failed to send a message: "SendError(..)"
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: BaseThreadInitThunk
  13: RtlUserThreadStart

ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification
panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\lsp-server-0.7.6\src\stdio.rs:28:37:
receiver was dropped, failed to send a message: "SendError(..)"
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: BaseThreadInitThunk
  13: RtlUserThreadStart

ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification

@dhruvmanila
Copy link
Member

Thank you for the details.

I'm not sure what's triggering the "Server received unexpected response..." during the shutdown but I don't think we're handling that well. Currently, it seems that we're returning an error but rather we should be returning a LSP error with InvalidRequest instead. I'll push a fix tomorrow for this which I think should at least avoid crashing the server.

@dhruvmanila dhruvmanila added bug Something isn't working and removed needs-mre Needs more information for reproduction labels Feb 19, 2025
dhruvmanila added a commit to astral-sh/ruff that referenced this issue Feb 20, 2025
## Summary

This PR should help in
astral-sh/ruff-vscode#676.

There are two issues that this is trying to fix all related to the way
shutdown should happen as per the protocol:
1. After the server handled the [shutdown
request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#shutdown)
and while waiting for the exit notification:
	
> If a server receives requests after a shutdown request those requests
should error with `InvalidRequest`.
    
But, we raised an error and exited. This PR fixes it by entering a loop
which responds to any request during this period with `InvalidRequest`

2. If the server received an [exit
notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#exit)
but the shutdown request was never received, the server handled that by
logging and exiting with success but as per the spec:

> The server should exit with success code 0 if the shutdown request has
been received before; otherwise with error code 1.

    So, this PR fixes that as well by raising an error in this case.

## Test Plan

I'm not sure how to go about testing this without using a mock server.
@dhruvmanila
Copy link
Member

@Akopov4 @Martin-Milbradt @DingXuefeng Hi, there's a new Ruff release that went out yesterday accompanied by a new VS Code extension release which contains a fix related to this. Can you try upgrading and see if the issue persists? If it still persists, then I think the logs should now provide more details than before.

@Martin-Milbradt
Copy link

Still erroring out (Windows proper this time):

ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification
ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification
[Error - 2:30:56 PM] Client Ruff: connection to server is erroring. Shutting down server.
[Error - 2:30:56 PM] Stopping server failed
Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:161:15)
    at writeGeneric (node:internal/stream_base_commons:152:3)
    at Socket._writeGeneric (node:net:958:11)
    at Socket._write (node:net:970:8)
    at writeOrBuffer (node:internal/streams/writable:572:12)
    at _write (node:internal/streams/writable:501:10)
    at Socket.write (node:internal/streams/writable:510:10)
    at c:\Users\TrueM\.vscode\extensions\charliermarsh.ruff-2025.10.0-win32-x64\dist\webpack:\ruff\node_modules\vscode-jsonrpc\lib\node\ril.js:91:29
    at new Promise (<anonymous>)
    at a.write (c:\Users\TrueM\.vscode\extensions\charliermarsh.ruff-2025.10.0-win32-x64\dist\webpack:\ruff\node_modules\vscode-jsonrpc\lib\node\ril.js:78:16)
    at y.doWrite (c:\Users\TrueM\.vscode\extensions\charliermarsh.ruff-2025.10.0-win32-x64\dist\webpack:\ruff\node_modules\vscode-jsonrpc\lib\common\messageWriter.js:100:34)
[Error - 2:30:56 PM] Stopping server failed
Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:161:15)
    at writeGeneric (node:internal/stream_base_commons:152:3)
    at Socket._writeGeneric (node:net:958:11)
    at Socket._write (node:net:970:8)
    at writeOrBuffer (node:internal/streams/writable:572:12)
    at _write (node:internal/streams/writable:501:10)
    at Socket.write (node:internal/streams/writable:510:10)
    at c:\Users\TrueM\.vscode\extensions\charliermarsh.ruff-2025.10.0-win32-x64\dist\webpack:\ruff\node_modules\vscode-jsonrpc\lib\node\ril.js:91:29
    at new Promise (<anonymous>)
    at a.write (c:\Users\TrueM\.vscode\extensions\charliermarsh.ruff-2025.10.0-win32-x64\dist\webpack:\ruff\node_modules\vscode-jsonrpc\lib\node\ril.js:78:16)
    at y.doWrite (c:\Users\TrueM\.vscode\extensions\charliermarsh.ruff-2025.10.0-win32-x64\dist\webpack:\ruff\node_modules\vscode-jsonrpc\lib\common\messageWriter.js:100:34)
ruff failed
  Cause: Server received unexpected message Response(Response { id: RequestId(I32(1)), result: None, error: None }) while waiting for exit notification

@dhruvmanila
Copy link
Member

dhruvmanila commented Feb 21, 2025

@Martin-Milbradt Can you make sure you're on the latest Ruff version (0.9.7)? Those messages don't look like the ones on latest version and Ruff shouldn't have crashed in this scenario:

https://github.com/astral-sh/ruff/blob/df9fbdce3af5af826115780f2d8c5cc4d91be650/crates/ruff_server/src/server/connection.rs#L116-L120

which should be just a warning log message with:

Server received unexpected message while waiting for exit notification: {message:?}

Notice that the message variable is at the end.

If you're using the latest VS Code extension (2025.10.0), then you can try setting ruff.importStrategy: "useBundled" to use the version that's bundled which should be the latest one. The client logs should also point out the version that's being picked up.

@Martin-Milbradt
Copy link

Looks good now, I forgot to update the ruff CLI, only updated the VSCode plugin.

@dhruvmanila
Copy link
Member

Looks good now, I forgot to update the ruff CLI, only updated the VSCode plugin.

Thanks for the update. I'll mark this as resolved then but happy to hear from others in this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants