vscode-rdbg icon indicating copy to clipboard operation
vscode-rdbg copied to clipboard

Issue with restarting the debugger along with a preLaunchTask

Open Rylon opened this issue 2 years ago • 4 comments

Hi! Thanks for this extension, amazing!

I'm using this along with a preLaunchTask in VS Code to spin up the development environment via Docker Compose, and it's working great, but I have only one small glitch - when I click the "restart" button in the debugger, the Compose environment stops, but then the preLaunchTask is not triggered again.

It sounds a bit like a similar glitch in the NodeJS debugger extension which is described here (https://github.com/microsoft/vscode/issues/104246) and the fix there was to make sure the preLaunchTask got called again, but I'm not sure if this is the same issue here.

What do you think?

Thanks!

Rylon avatar Feb 21 '23 17:02 Rylon

What is preLaunchTask ?

ko1 avatar Mar 07 '23 16:03 ko1

Can we repro on our machine with small steps?

ko1 avatar Mar 07 '23 16:03 ko1

The preLaunchTask is used to run another task before the debugger task runs, I use it to launch a Rails app from a Docker Compose project.

The entrypoint of the app in Docker Compose detects RUBY_DEBUG_ENABLED and if that is true, it exports additional environment variables:

# entrypoint of docker app
if [ $RUBY_DEBUG_ENABLED == 'true' ]; then
  export RUBY_DEBUG_OPEN=true
  export RUBY_DEBUG_HOST=0.0.0.0
  export RUBY_DEBUG_PORT=12345
fi
rails server -b 0.0.0.0

The reason for this is we can't have multiple Ruby processes trying to bind to that debug port, for example if you were to have these set all the time, if you tried to run docker compose app rails console, the debugger would attempt to bind in the console too, and fail because the port is already allocated.

The VS Code tasks and launch configs look like this:

# .vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "isBackground": true,
      "label": "Run via Docker",
      "type": "shell",
      "command": "docker compose up",
      "options": {
        "env": {
          "RUBY_DEBUG_ENABLED": "true",
        }
      },
      "presentation": {
        "reveal": "always",
      },
      "problemMatcher": {
        "owner": "custom",
        "pattern": {
          "regexp": "____"
        },
        "background": {
          "activeOnStart": true,
          "beginsPattern": "DEBUGGER: Debugger can attach via TCP/IP (0.0.0.0:12345)",
          "endsPattern": "Use Ctrl-C to stop"
        }
      }
    }
  ]
}
# .vscode/launch.json
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "rdbg",
      "name": "Run and debug with rdbg",
      "request": "attach",
      "debugPort": "localhost:12345",
      "localfsMap": "/app:${workspaceFolder}",
      "preLaunchTask": "Run via Docker",
    }
  ]
}

Rylon avatar Mar 10 '23 18:03 Rylon

Thank you for details!!

Now I'm not sure how to solve it but I'll try it. If we can support it, maybe we need to add the doc about this feature.

ko1 avatar Mar 20 '23 08:03 ko1