-
Notifications
You must be signed in to change notification settings - Fork 288
Debugging not working with ruby on rails #426
Comments
Precision: debugging a barebone ruby script works ok (breakpoints are met). |
Tried lots of different things but can't get it to work. I use this new config following the guide: {
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"program": "/home/mic/.rbenv/versions/2.6.1/bin/rails",
"cwd": "${workspaceRoot}",
"showDebuggerOutput": true,
"args": [
"server"
]
} I updated debase & ruby-debug-ide, now In a barebone console, doing Can't really see where to go from there. Any pointer? |
Ok, actually I realize that the issue is that the debugger does not attach to the process. If I run When using Can't think of a way to debug that. Any hint? |
Tried to disable SPRING as stated in this thread ruby-debug/ruby-debug-ide#152 But with no luck either. It really seems that when using the If I hit "PAUSE" when it hangs, it stops in the Puma code (the webserver). So I think the debugger attaches to the Puma process instead of the worker thread. Is it possible to check / force the behavior? |
Dup of #316 Sorry, I haven't focused on the debugger at all. It's coming... |
@MicMicMon I was struggling with the same issue on my machine. RDebug on the command line was not starting the rails server unless I did Ctrl+C once. My colleague right next to me, who jumped into the project a few days later with a fresh installation of VSCode (we are both just on-boarding for a Ruby project coming from other IDE backgrounds) was not facing any issues and could debug from his first launch. I already had given up, but I couldn't accept that it was working for him and not for me, we were both running on Docker with same env variables, so in theory the basic project setup or any kind version mess didn't seem to be a problem. The attached process and the debugger seemed to be connected, because killing the attached process would kill the debugger process. My last resort was Wireshark to see what was going on the TCP networking level. Finally I had my Heurika moment. The attached IDE debug process was sending breakpoint positions to the debugger server process, including breakpoints from other projects. I removed all breakpoints and restarted the process and click – the server starts and I was able to break in my code. Hope this helps anyone setting up his debugger and also @wingrunr21 to make the debug attaching more robust. |
@tillkolter thanks for this information. When you say "breakpoints from other projects", do you mean:
Thanks! |
@wingrunr21 It was never a matter of location of the breakpoints, it was a matter of being disabled (my old spurious breakpoints had been disabled) As soon as there is at least one breakpoint in the list, which is disabled, the debugged process is not starting, no matter if the breakpoint refers to a file within the project or not. As soon as I re-enabled all breakpoints, the process starts just fine. Hope this helps. |
Thanks for the tip @tillkolter ! Unfortunately, it still doesn't work for me :( |
For everyone's info, there is a bug with the debugger and rails5. The gem bootsnap causes the breakpoints to not work (see https://youtrack.jetbrains.com/issue/RUBY-20684). If you can get the VSCode debugger to start and properly connect to the When you have -d running, set a breakpoint and verify that rdebug-ide is receiving it properly. You'll see the following immediately when you startup if the breakpoint is set before you launch:
I have setup a RAILS_DEBUG environment flag that disables a lot of these optimizations to get the debugger working. The flag currently disables multiple workers in puma and disables loading bootsnap in |
Thanks for you help @jonmchan. |
Thanks for your help @jonmchan Didn't understand your What versions of |
Run |
Don't know how to do that. What's your config file in VSCode? Is there a command to give the Sorry, I'm not familiar with this setup :\ |
Had the same issue. @tillkolter your method worked for me. Clicking "remove all breakpoints", and starting the debug process again worked for me! Now I can add new breakpoints as needed. |
this is the point, I removed all breakpoints, and then I can use debugger |
Hi @MicMicMon |
Nope, unfortunately :( Quit trying after a while, I'm totally blind on how it works because I don't know those debug technologies. I'm trying to switch to Windows & WSL / VSCode right now, I will give it another shot with this setup. |
The fix to that is to start puma in single thread mode. export the following variables specifically:
https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#config |
I remember trying that at the time but it didn't work either. |
I'm sorry, it wasn't 1, it was 0. Here is my exact start script:
This script works for me to do debugging. |
@jonmchan This worked for me. Thanks a lot. |
If i recall correctly, |
Using It was very simple and didn't have to do with stray leftover breakpoints, or threads, or concurrency. Most of the tutorials for this tell you to configure your
However, this won't work unless your Docker filesystem has the same shape as the local filesystem. You will see that it used my Mac filesystem:
Once I fixed this, it set the breakpoint on the proper path for what the rails server sees, and then my breakpoints started working.
Hope this helps! |
Here is a working launch.json for me:
You can grab your absolute path to ruby-debug-ide with It wouldn't work for me with the absolute path to the bundler gem (basically a path similar to the ruby-debug-ide path above - don't use that, use the shim or whatever RVM calls it) Was having a monstrous time getting this to work like everyone else here - but this is the working configuration in my case. I also manually installed rdebug-ide and debase gems - meaning I https://lankydan.dev/2017/05/12/debugging-a-rails-server-in-visual-studio-code I absolutely had to set WEB_CONCURRENCY to 0 and MAX_THREADS to 1 These are set in my puma.rb config file - they can be set other ways as other posters have commented. But don't forget this. |
Thanks @tgmerritt - this was the only way for me to get this to work. Here's a little more of my config below with all the In my
And my
|
This worked for me too. Thanks a lot. Tips: do not forget to set the database pool to enough value to avoid
It works for me. Thanks a lot. BTW, do not forget to assign enough database pool in database.yml file with |
I feel like getting this to work properly was like summiting Everest... Ultimately @jonmchan solution worked for me, but I'll comment everything I did here and some of my configs to be super clear for everyone in the future who is ramping on rails for the first time:
Some other things I ran into along the way, and misinformation I ran into, that I had to fix that may help people who are brand new:
Hopefully this helps, good luck getting this to work (you're going to need it...)! |
@trevorbye could you try adding the environment variables to the |
"https://gist.github.com/alif-bae/dfe8c6612d5b42dd5b5be8cefdd4a0c7" does not exist anymore, but "https://gist.github.com/alifbae/dfe8c6612d5b42dd5b5be8cefdd4a0c7" is, redirecting you to "https://stackoverflow.com/questions/51722136/how-do-you-run-and-debug-ruby-on-rails-from-visual-studio-code". PATH comes from your env var (e.g. echo $PATH) According to https://stackoverflow.com/a/60012122, p.s. I still haven't gotten it to work tho |
Your environment
vscode-ruby
version: 0.21.0Expected behavior
Should break on breakpoint.
Actual behavior
Does not break on breakpoints after starting
rails server
and making a request that runs the code where I want a breakpoint.If I add the breakpoint before running the debugger, it hangs without more context when supposedly hitting the breakpoint.
If I add the breakpoint after running the debugger, the breakpoint is simply ignored.
My config is:
In the debug console, I properly have
Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2, file filtering is supported) listens on 127.0.0.1:1234
.Tried removing / adding
byebug
,debase
andruby-debug-ide
fromGemfile
with no luck.The text was updated successfully, but these errors were encountered: