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

Debugging session is ended early when forked process exits

Open davidtaylorhq opened this issue 3 years ago • 1 comments

When a ruby process is forked, the debugger initially works as expected. Breakpoints fire correctly in both the parent and child processes.

However, when the child fork exits, the VSCode debugging session seems to end prematurely. That means that further breakpoints in the parent process do not fire correctly.

Here's a minimal reproduction:

$start = Time.now

def log(msg)
  time = (Time.now - $start).round(3)
  puts "[t=#{time}s] [pid=#{Process.pid}] #{msg}"
end

log "Starting script"

fork do
  log "Fork started"
  sleep 1
  # sleep # (uncommenting this allows the main process debugger to work correctly)
  log "Fork done"
end

sleep 3

log "Set breakpoint on this line" # <<<< Breakpoint
log "Done script"

This produces the output

❯ rdbg --command --open --stop-at-load --sock-path=/var/folders/c7/
3jzsz23s16l3_jtzrttkxwfw0000gn/T/ruby-debug-sock-501/ruby-debug-david-51037 -- ruby hello_world.rb 
DEBUGGER: Debugger can attach via UNIX domain socket (/var/folders/c7/3jzsz23s16l3_jtzrttkxwfw0000gn/T/ruby-debug-sock-501/ruby-debug-david-51037)
DEBUGGER: Connected.
DEBUGGER: wait for debugger connection...
DEBUGGER:  BP - Line  /Users/david/hello_world.rb:19 (line) is activated.
[t=0.0s] [pid=51105] Starting script
DEBUGGER: Attaching after process 51105 fork to child process 51106
DEBUGGER[hello_world.rb#51106]: Connected.
[t=0.002s] [pid=51106] Fork started
[t=1.004s] [pid=51106] Fork done
DEBUGGER[hello_world.rb#51106]: Disconnected.
DEBUGGER[hello_world.rb#51105]: Disconnected.
[t=3.003s] [pid=51105] Set breakpoint on this line
[t=3.004s] [pid=51105] Done script

The VSCode 'debug' environment appears to terminate at the same time as 'fork done', and the breakpoint is never fired.


Launch configuration:

{
  "name": "Debug Script",
  "command": "ruby",
  "script": "hello_world.rb",
  "request": "launch",
  "type": "rdbg",
},
❯ ruby --version
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin21]

❯ gem info debug

*** LOCAL GEMS ***

debug (1.6.3)
    Author: Koichi Sasada
    Homepage: https://github.com/ruby/debug
    Licenses: Ruby, BSD-2-Clause
    Installed at: /Users/david/.rvm/rubies/ruby-3.1.3/lib/ruby/gems/3.1.0

    Debugging functionality for Ruby

Extension version v0.0.11

davidtaylorhq avatar Dec 23 '22 14:12 davidtaylorhq

Now vscode-rdbg doesn't support fork well. Thank you for the report.

ko1 avatar Dec 23 '22 18:12 ko1