microsoft / vscode-recipes

MIT License
5.86k stars 577 forks source link

Rails server terminates threads when debugging without WEB_CONCURRENCY=0 #318

Open tohagan opened 2 years ago

tohagan commented 2 years ago

VS Code 1.63.2 / Rails 6.0.4 / Puma gem 4.3

I'm running Rails and VSCode with WSL 1.0 with Ubuntu 20.04.
I start up VSCode with WSL. 1.0 (WSL 2.0 had network routing problems for me).

If WEB_CONCURRENCY > 0 via config/puma.rb, Puma will run in cluster mode with multiple concurrent worker threads and terminate them if they appear to be not returning a response after a timeout period. When debugging in a worker thread I observe that breakpoints work, I make a few steps in the code and then the debugger stops responding at all. A log message indicates that Puma has terminated a worker thread. This commonly occurs with breakpoints set or even if just running slower with a large app running in the debugger.

This is fixed by setting WEB_CONCURRENCY=0.

So I'd recommend adding the following to Debug Rails Server launch.json ...

"env": {
  "WEB_CONCURRENCY": "0"
}

Here's my complete config for Debug Rails server ...

{
  "name": "Debug Rails server",
  "type": "Ruby",
  "request": "launch",
  "cwd": "${workspaceRoot}",
  "useBundler": true,
  "pathToBundler": "/path/to/rubygem/wrappers/bundle",
  "pathToRDebugIDE": "/path/to/rubygem/gems/ruby-debug-ide-x.x.x/bin/rdebug-ide",
  "program": "${workspaceRoot}/bin/rails",
  "args": [
    "server",
    "-p",
    "3000"
  ],
  "env": {
    "WEB_CONCURRENCY": "0"
  }
}