Debugger cannot attach to running process
Operating System
Windows 11 - WSL 2 (Ubuntu) / Dev Containers
Ruby version
3.3.0
Project has a bundle
- [X] Has bundle
Ruby version manager being used
no manager
Description
Running VSCode on Windows / WSL 2 with Dev Containers, the extension is unable to find the socket created by the rdbg process.
My Dockerfile has the following CMD directive:
CMD [ "bundle", "exec", "rdbg", "-O", "-n", "-c", "--", "bin/rails", "s", "--early-hints", "-b", "0.0.0.0" ]
It starts the server correctly and logs the socket creation (see first line of Container log):
But when I start the debugger I see the message:
The debugger is working in other contexts like for instance debugging a test case:
From the error message, it seems like the attachDebuggee function is not finding the sock (I checked the file location in the container as well as permissions).
This is weird, if run bundle binstub debug and replace the Docker CMD from bundle exec rdbg ... to bin/rdbg ... the debugger can attach to the process, but this is not a consistent behavior. Once in a while the debugger stops finding the socket.
Thank you for the bug report! @st0012 do you have any ideas on what could be happening here? I remember you mentioning some stuff about bin/rdbg.
I'm seeing the same issue without using a container, on MacOS.
Starting rails with bundle exec rdbg -O -n -c -- bin/rails server -p 3000:
launch.json:
{
"type": "ruby_lsp",
"request": "attach",
"name": "Attach to existing dashboard-server",
},
Result of running attach to existing dashboard-server:
@snickell does it work with the debug gem binstub?
@gabrielso I don't know a lot about the debug gem, could you suggest how I might test that?
You certainly have the debug gem installed (as is a dependency of a Rails project), which means you can invoke it on the terminal bundle exec rdbg, but if you genera a binstub (bundle binstub debug will generate the bin/rdbg wrapper) you can start your application with bin/rdbg -O -n -c -- bin/rails server -p 3000.
My assumption is that the wrapper was creating a favorable condition (maybe related to file/socket ownership since the Docker runs as root). That worked but started failing again after a couple of days.
By the way, I copied the Dev Container setup from the Rails main branch and it is working so far (although VS Code still hangs from time to time when I detach the debugger), that one uses the "official" Dev Container image for Ruby provided by Microsoft whereas my previous setup was relying on an image I built "from scratch".
There are probably some fixes on MS's image to make it work more reliably since they're specifically made to be Dev Containers.
I can share the setup if you're interested in testing.
I can reproduce the issue as well, with a different system
Operating System: Ubuntu 22.04
Ruby version 3.2.4
Project has a bundle: Yes
Ruby version manager being used: rbenv
I did a clean install of the shopify ruby extension pack
Actually I found a way to make it work, riiight before I was about to give up:
in launch.json specify the port of your rdbg like this:
{
"type": "ruby_lsp",
"name": "Attach debugger",
"request": "attach",
"debugServer": 4711
}
and specify the same port when running rails server in the console:
bundle exec rdbg -O -n --port 4711 -c -- bin/rails server --early-hints
This issue is being marked as stale because there was no activity in the last 2 months
@LouisKottmann really thanks for helping , this is make me can not debug from docker to vscode for long time!!!
for any one want to debug rails from vscode inside docker
ruby version 3.3.3
change your compose file like this :
ports:
- 3000:3000
- 1234:1234
command: ['bundle', 'exec', 'rdbg', '--open', '--nonstop', '--port=1234', '--command', '--', 'rails', 's', '-p', '3000', '-b', '0.0.0.0']
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "Remote Debug - Rails", "type": "rdbg", "request": "attach", "debugPort": "localhost:1234", "localfsMap": "/app:${workspaceFolder}", "rdbgPath": "/usr/local/bundle/bin/rdbg", "showDebuggerOutput": true } ] }
add to gem file
gem 'debug', '~> 1.8'