Open Nowaker opened 8 months ago
Any suggestions on what to do? If I'm given a quick primer on where to go and put some console.log and alike to provide more information on what exactly is failing, I'm happy to do it. Especially: tell me where you suspect is the line that triggers the "Debugger exited with status 1", and I'll take it from there.
Thank you for the bug report! In the latest version of the extension, we started printing the debug server backtrace to the debug console if spawning fails.
If you try again, do you see the backtrace? That might help uncover what's failing.
In the latest version of the extension
Unfortunately, the latest version doesn't work for me at all but that's unrelated to this issue. https://github.com/Shopify/vscode-ruby-lsp/pull/923#issuecomment-1925444162 I'll come back to this one when RVM ends up working in the pre-release version.
This issue is being marked as stale because there was no activity in the last 2 months
We have shipped better RVM support in the stable version of the extension. If you can try this again, hopefully the debug console will print whatever errors occurred in the server, which can help us understand what's going on.
This issue is being marked as stale because there was no activity in the last 2 months
I'll have a look this week. Sorry for the wait.
I'll close this one for now. Since we shipped the upgraded integration for RVM, we have not received any related bug reports, so I'm hoping this has been fixed too.
If that's not the case, please do re-open.
Aight, thank you @vinistock.
Hi. Unfortunately i am currently experiencing the same issue after the installing the most recent version of the vs code extension and the most up to date ruby-lsp gem. There are no error reports in the ruby-lsp output of vscode.
I also tried running the command manually and attaching the debugger afterwards, which works well.
@jklimke do you happen to have bundler configs for your project or user? I suspect it could be related to https://github.com/Shopify/ruby-lsp/issues/2519.
@vinistock As far as i know i do not have configured a particular bundler config
The only thing that i have configured is the number of jobs for bundler.
bundle config
Settings are listed in order of priority. The top value will be used.
jobs
Set via BUNDLE_JOBS: 8
I meet the same problem, even the .ruby-lsp folder is not created! And I will exit if I click the debug button
@vinistock It turned it this issue wasn't caused by RVM. I've not been encountering this issue for a while now, until I was able to trigger it again. Here's what happened.
First, I decided to bump appsignal
gem:
modified: Gemfile.lock
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
- appsignal (3.13.1)
+ appsignal (4.0.8)
bundle exec puma
would normally use it. However, I noticed that Ruby LSP Debugger would load an older version of appsignal
, inconsistent with what my Gemfile.lock
wants!
So I set a breakpoint before Appsignal.set_error
, then step into it, and stackframes point to appsignal-3.13.1
.
This shouldn't really ever happen, given Ruby LSP uses Bundler when present on the project. But it is happening. So I do gem uninstall appsignal -v 3.13.1
and... I get this again:
So, I install it back with gem install appsignal -v 3.13.1
, and debug starts as normal again.
I'm in a pickle here. Unsure why/how Ruby LSP decides it should use an incorrect version of a dependency... And how it comes up with that version number to use in particular, given that gem version doesn't exist.
Any ideas what I could do, and what data to supply back, to help find the cause of this?
I checked https://github.com/Shopify/ruby-lsp/issues/2519 and it seems unrelated. And I'm rocking Ruby LSP extension v0.7.20 so it should be fixed if it's at play.
Whoa! Ruby LSP does not obey Gemfile.lock!
A change in Gemfile.lock
was totally ignored:
- appsignal (3.13.1)
+ appsignal (4.0.8)
It also wants a change in Gemfile
to work:
-gem 'appsignal'
+gem 'appsignal', '~> 4.0'
So when Gemfile
and Gemfile.lock
are both modified, Ruby LSP picks up appsignal-4.0.8
just fine - debugger starts, and I can step into it.
...This is of course totally unexpected, since Gemfile.lock
is in charge of deciding the exact versions of dependencies to use when they're not defined in Gemfile
, and of course for all dependency tree. Gemfile
doesn't need to be updated in any way. A version bump performed via Gemfile.lock
is absolutely fine... except for Ruby LSP. ;)
Now that I know the root cause, I can keep the version number of this dependency in my Gemfile, but let's take a step back and come up not just with a fix, but a generic logging mechanism that could help catch problems like these. What could "Ruby LSP" print in "Output" window to help understand the issue at hand? What's currently printed there is irrelevant to debugging this. And that exit 1 comes from somewhere... Nothing in stdout/stderr as Ruby LSP tries to run it? There could be a clue about missing appsignal-3.13.1
. At least that would give a hint it's about dependency resolution.
I also noticed that after the first successful run of Ruby LSP with appsignal-4.0.8
, I can now remove my Gemfile
change and Ruby LSP is still activating appsignal-4.0.8
. It no longer forces appsignal-3.13.1
in. That sounds like a bug in Ruby LSP's caching mechanism, I presume.
Thank you very much for all the information, this is extremely helpful. This is what I believe to be happening:
.ruby-lsp
to automatically include the ruby-lsp
and debug
gemsBased on what you're saying, we're launching the debugger using the lockfile before it was updated somehow. The puzzling part for me is: are you not seeing the language server restart automatically upon modifying the lockfile?
I would've expected the restart to automatically correct the custom lockfile, which would then make launching the debugger work.
EDIT:
I also just realized this: the Ruby LSP debug client only attaches the debugger to the running process, but it doesn't control which dependencies are loaded by that process. Are you restarting the process you want to attach the debugger to after upgrading the gem?
That could explain the behaviour you're seeing, since the process would be using the old version of the gem.
Thanks for getting back to me @vinistock. Appreciate your help here.
If your lockfile changes, we restart the language server, which re-runs the custom bundle logic, detects that the main lockfile has been modified and re-generates everything from scratch
Uhm... And if I execute bundle update appsignal
or git pull
when my VS Code / Ruby LSP isn't running, is my debugging broken forever now? ;-) Just like it was for me for a couple months before it randomly started working again on this computer. (Supposedly, by updating Gemfile
, which would then trigger a condition where the whole thing gets fixed again)
The puzzling part for me is: are you not seeing the language server restart automatically upon modifying the lockfile?
Unsure, since I use my own terminal to execute bundle update <dependency name>
whenever needed, so my VS Code isn't in focus. Or I may be starting my work, and therefore git pull
first, and then code .
after that. I don't use a teeny tiny VS Code terminal on a daily basis.
If your lockfile changes, we restart the language server, which re-runs the custom bundle logic
I use VS Code on a daily basis. I also turn off my computer every day. That means Ruby LSP starts from scratch many times. However, the issue persisted across Ruby LSP restarts. That indicates it's not really about Gemfile.lock
being watched for changes, but rather, something in Ruby LSP activation code not picking up on the fact Gemfile.lock
was modified, and using its stale version for its own demise instead (or using some files/caches that were created based on the stale version of Gemfile.lock
).
I also just realized this: the Ruby LSP debug client only attaches the debugger to the running process, but it doesn't control which dependencies are loaded by that process. Are you restarting the process you want to attach the debugger to after upgrading the gem?
Please don't get distracted by request=attach
being mentioned here. :-) It was to give you an example that I am able to run the debug fine if I attach to it, but request=launch
gets me exit 1 and no indication about what is going on and why.
This issue is solely about request=launch
returning with exit status 1 when some Gemfile.lock
changes were made that Ruby LSP isn't aware of.
@Nowaker can you share the contents of your vscode debugging configuration?
{
"name": "Rails",
"type": "ruby_lsp",
"request": "launch",
"program": "puma" # or bundle exec puma, it doesn't matter, same problem
},
And if I execute bundle update appsignal or git pull when my VS Code / Ruby LSP isn't running, is my debugging broken forever now? ... Unsure, since I use my own terminal to execute bundle update
whenever needed, so my > VS Code isn't in focus. Or I may be starting my work, and therefore git pull first, and then code . after that. I don't use a teeny tiny VS Code terminal on a daily basis. ... I use VS Code on a daily basis. I also turn off my computer every day. That means Ruby LSP starts from scratch many times
Whenever the server launches, be it due to a restart, re-opening VS Code, automatic file watcher restart or any other trigger, we always check if the contents of the main lockfile are not matching the contents of the custom lockfile, so that we can then re-copy and start from scratch (see this line).
Updating a gem, even if you do it in a separate terminal or with the editor closed, should make no difference. When you open VS Code, it will compare the SHA digest of the previous lockfile content vs the current one and re-generate if needed.
Based on this comment
It also wants a change in Gemfile to work:
I suspect there's some Bundler related issue at play. We don't even watch the Gemfile or do anything with it, since what controls the versions is the lockfile. The only impact that adding a constraint to the Gemfile would have is to force Bundler to resolve versions in a certain way.
Do you happen to have any global (~/.bundle/config
) or project (~/path/to/project/.bundle/config
) Bundler settings? We did just merge #2535, which fixes handling of Bundler setttings.
Do you happen to have any global (~/.bundle/config) or project (~/path/to/project/.bundle/config) Bundler settings? We did just merge https://github.com/Shopify/ruby-lsp/pull/2535, which fixes handling of Bundler setttings.
Yes:
% cat ~/.bundle/config
---
BUNDLE_JOBS: '20'
BUNDLE_RETRY: '5'
BUNDLE_BUILD__NOKOGIRI: "--use-system-libraries"
% cat .bundle/config
---
BUNDLE_WITHOUT: "skip_arch"
But I was already on that version when I found the cause of this issue.
I suspect there's some Bundler related issue at play. We don't even watch the Gemfile or do anything with it, since what controls the versions is the lockfile. The only impact that adding a constraint to the Gemfile would have is to force Bundler to resolve versions in a certain way.
I mean, it surely is about Bundler. But it isn't a Bundler issue alone - it's an issue triggered by Ruby LSP. Bundler alone works fine, I can bundle exec puma
and it loads the correct dependency. Even when I execute the command Ruby LSP advertises to execute when debugging, it starts, listens, and I can connect to that socket via request=attach
. But when it's request=launch
executed by Ruby LSP, an older version of appsignal is being pulled in. If you happen to still have it installed locally, it will work. But if you gem uninstall
it, then it's exit status 1 and no indication as to why it's exit 1.
It's clear as day it's something in Ruby LSP triggering this incorrect behavior, and all my experience tells me it's a caching mechanism. Old Gemfile.lock? I can't tell.
Ruby LSP has some caching - a quick search reveals this one, for example: https://github.com/Shopify/ruby-lsp/blob/a4f5a2d780950816829bd1372f559979d947e7cd/lib/ruby_lsp/setup_bundler.rb#L94. I don't know if it's related to my issue.
And I'm also unsure if this entire bundle setup thing is happening for request=launch
. And if so, why? Since it's just an rdbg
call, which requires debug
in Gemfile
(which mine has), there is absolutely no need for Ruby LSP to perform any of what I'm seeing in RubyLsp::SetupBundler
. I understand it's important for the language server, especially to gem its version up to date, but I don't see how it has any use for request=launch
in particular.
2024-01-22 20:33:18.537 [info] Spawning debugger in directory /home/nowaker/projekty/modern/worldmodern
2024-01-22 20:33:18.537 [info] Command bundle exec rdbg --open --command --sock-path=/tmp/ruby-lsp-debug-sockets/ruby-debug-worldmodern-0.sock -- puma
2024-01-22 20:33:18.537 [info] Environment {"RAILS_DEBUG":"true","SHELL":"/usr/bin/zsh" .......
AFAIR, I even replicated the same environment variables back then. And it would still just start, and listen. And then I would attach from VS Code. But having the plugin do it, it exits 1.
If we're back to square one, let's go back to February:
Any suggestions on what to do? If I'm given a quick primer on where to go and put some console.log and alike to provide more information on what exactly is failing, I'm happy to do it. Especially: tell me where you suspect is the line that triggers the "Debugger exited with status 1", and I'll take it from there.
In the latest version of the extension, we started printing the debug server backtrace to the debug console if spawning fails. If you try again, do you see the backtrace? That might help uncover what's failing.
Nope. No backtrace. Still the same output as before.
I've recorded a video for you to see how easy it is for me to reproduce this issue and show it's about an old dependency being retained (somehow).
gem appsignal
in Gemfile. Have it locked at 3.11.1 in Gemfile.lock.bundle exec puma
. Shows 3.11.1 in use.bundle update appsignal
without any changes in Gemfile. Only Gemfile.lock has it.bundle exec puma
. Shows 4.0.9 in use.gem uninstall appsignal -v 3.11.1
bundle exec puma
. Shows 4.0.9 in use.gem 'appsignal'
to gem 'appsignal', '4.0.9'
Gemfile
to gem 'appsignal', '4.0.9'
Gemfile
to gem 'appsignal'
Gemfile
to gem 'appsignal', '~> 3.0.0
, then run bundle update appsignal
Gemfile
to gem 'appsignal'
gem update appsignal
(to bump to 4.0.9)Gemfile
to gem 'appsignal', '4.0.9'
Gemfile
to gem 'appsignal'
Gemfile.lock
to appsignal-4.0.9It's pretty clear my Gemfile.lock
isn't in charge when running via Ruby LSP. It's like you use it for the first time, but subsequent changes are ignored in it, unless I make a change in Gemfile
.
Operating System
Linux
Ruby version
3.3.0 / 3.1.4
Project has a bundle
Ruby version manager being used
rvm
Description
Executing the exact same command from the log
bundle exec rdbg --open --command --sock-path=/tmp/ruby-lsp-debug-sockets/ruby-debug-worldmodern-0.sock -- puma
succeeds. And I can attach a debugger from there with no issue, so something isn't adding up.I tried bumping the dependencies, but it didn't help. Still exit 1.
Neither Ruby 3.3.0 nor Ruby 3.1.4 works on this computer. Linux + RVM.
The exact same application with
launch.json
on my other computer works. Mac + RVM.