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

Extra output in LSP response causes crash during formatting #2284

Closed
thatbudakguy opened this issue Jul 10, 2024 · 8 comments
Closed

Extra output in LSP response causes crash during formatting #2284

thatbudakguy opened this issue Jul 10, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@thatbudakguy
Copy link

Description

Similar problem to #1723, but the setup is quite different:

  • using rbenv, not rvm
  • using extension version v0.7.11 with bundler 2.5.14, ruby 3.2.3
  • using vscode 1.91.0

I'm working on https://github.com/geoblacklight/geoblacklight, which uses standardrb as the formatter.

The LSP starts up fine and correctly detects my shell, version manager, etc. The problem only occurs when I ask it to format a file using the VSCode command palette.

Reproduction steps

  1. Start the Ruby LSP using VSCode
  2. Open a Ruby file
  3. Open the command palette and choose "Format file"
  4. The command hangs

Code snippet or error message

2024-07-10 13:43:35.668 [info] (geoblacklight) [Error - 1:43:35 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"inspecting 1 file\n\n\n1 file inspected, no offenses detected\ncontent-length":"39"}
Shutting down server.
2024-07-10 13:43:35.669 [info] (geoblacklight) Shutting down Ruby LSP...

2024-07-10 13:43:35.669 [info] (geoblacklight) [Error - 1:43:35 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"41,\"result\":null,\"jsonrpc\":\"2.0\"}Content-Length: 39"}
Shutting down server.
2024-07-10 13:43:37.670 [info] (geoblacklight) [Error - 1:43:37 PM] Stopping server timed out
2024-07-10 13:43:37.674 [info] (geoblacklight) [Error - 1:43:37 PM] Stopping server failed
2024-07-10 13:43:37.675 [info] (geoblacklight) Error: Stopping the server timed out

It looks like the output of rubocop is being mixed in, but:

  • I don't have the rubocop extension installed or configured
  • This project uses standardrb, and the LSP correctly detected that

Could this be a problem with the Standard Ruby LSP addon? I noticed that I don't encounter this problem on other projects that do use the LSP but use rubocop instead of standardrb.

@thatbudakguy thatbudakguy added the bug Something isn't working label Jul 10, 2024
@alexcameron89
Copy link

Hello, I'm also seeing the same issue. Here is the output from mine:

2024-07-11 11:50:21.056 [info] (payment-service) Initializing Ruby LSP v0.17.6...

2024-07-11 11:50:21.080 [info] (payment-service) Finished initializing Ruby LSP!

2024-07-11 11:50:21.123 [info] (payment-service) [Standard Ruby] Activating Standard Ruby LSP addon v1.39.0

2024-07-11 11:50:21.369 [info] (payment-service) [Standard Ruby] Initialized Standard Ruby LSP addon 1.39.0

2024-07-11 11:50:21.369 [info] (payment-service) Activating Ruby LSP Rails addon v0.3.10

2024-07-11 11:50:21.377 [info] (payment-service) Ruby LSP Rails booting server

2024-07-11 11:50:21.580 [info] (payment-service) [Error - 11:50:21 AM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"inspecting 1 file\n\n\n1 file inspected, no offenses detected\ncontent-length":"60"}
Shutting down server.
2024-07-11 11:50:21.581 [info] (payment-service) [Error - 11:50:21 AM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"1,\"result\":{\"kind\":\"full\",\"items\":[]},\"jsonrpc\":\"2.0\"}Content-Length: 118"}
Shutting down server.
2024-07-11 11:50:21.584 [info] (payment-service) Shutting down Ruby LSP...

2024-07-11 11:50:21.599 [info] (payment-service) [Error - 11:50:21 AM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"2,\"result\":[{\"name\":\"Standard Ruby\",\"errored\":false},{\"name\":\"Ruby LSP Rails\",\"errored\":false}],\"jsonrpc\":\"2.0\"}Content-Length: 39"}
Shutting down server.
2024-07-11 11:50:21.600 [info] (payment-service) /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.17.6/lib/ruby_lsp/base_server.rb:83:in `push': queue closed (ClosedQueueError)
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.17.6/lib/ruby_lsp/base_server.rb:83:in `block in start'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.17.6/lib/ruby_lsp/base_server.rb:39:in `start'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11480/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/sorbet-runtime-0.5.11480/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.17.6/exe/ruby-lsp:110:in `<top (required)>'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/bin/ruby-lsp:25:in `load'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/bin/ruby-lsp:25:in `<top (required)>'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `load'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli/exec.rb:23:in `run'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli.rb:451:in `exec'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli.rb:34:in `dispatch'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli.rb:28:in `start'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.9/exe/bundle:28:in `block in <top (required)>'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.9/exe/bundle:20:in `<top (required)>'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/bin/bundle:25:in `load'
	from /Users/alexkitchens/.rbenv/versions/3.3.2/bin/bundle:25:in `<main>'

2024-07-11 11:50:21.606 [info] (payment-service) [Error - 11:50:21 AM] Server process exited with code 1.
2024-07-11 11:50:21.607 [info] (payment-service) [Error - 11:50:21 AM] Connection to server got closed. Server will not be restarted.
2024-07-11 11:50:21.608 [info] (payment-service) [Error - 11:50:21 AM] Stopping server failed
2024-07-11 11:50:21.608 [info] (payment-service)   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-07-11 11:50:21.608 [error] (payment-service) Error starting the server: Cannot read properties of undefined (reading 'errorMessage')
2024-07-11 11:50:21.608 [info] (payment-service) [Error - 11:50:21 AM] Stopping server failed
2024-07-11 11:50:21.608 [info] (payment-service)   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-07-11 11:50:21.608 [info] (payment-service) [Error - 11:50:21 AM] Stopping server failed
2024-07-11 11:50:21.608 [info] (payment-service)   Message: Pending response rejected since connection got disposed
  Code: -32097 
2024-07-11 11:50:21.608 [info] (payment-service) [Error - 11:50:21 AM] Stopping server failed
2024-07-11 11:50:21.608 [info] (payment-service)   Message: Pending response rejected since connection got disposed
  Code: -32097 

@vinistock
Copy link
Member

Thank you for the bug report! This does indeed look like a problem in the Standard addon, which seems to be printing to STDOUT. In language servers, STDIN and STDOUT are reserved for editor/server communication, which is why simply printing to STDOUT is enough to break the connection and crash the server.

For RuboCop, we force the usage of the base formatter, which doesn't output anything (thus preventing it from breaking the client/server connection).

cc @searls

@searls
Copy link

searls commented Jul 12, 2024

Looks like you're on [email protected]. This should have been fixed in 1.39.1

@vinistock
Copy link
Member

Awesome! Standard users, please upgrade to 1.39.1.

@vinistock vinistock closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2024
@thatbudakguy
Copy link
Author

Confirming that 1.39.1 fixes this for me. Cheers!

@marcoslhc
Copy link

I'm not using Standard so I don't know how or where to update Standard to 1.39.1. Is there a guide somewhere?

@searls
Copy link

searls commented Aug 1, 2024

@marcoslhc if standard isn't in your Gemfile (or, if your project lacks a Gemfile) isn't installed on your system, this shouldn't be causing a crash for you. Is it?

@marcoslhc
Copy link

marcoslhc commented Aug 1, 2024 via email

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

No branches or pull requests

6 participants