ruby-debug / ruby-debug-ide

An interface which glues ruby-debug to IDEs like Eclipse (RDT), NetBeans and RubyMine.
https://www.jetbrains.com/ruby/features/ruby_debugger.html
Other
370 stars 83 forks source link

Add fixed port range for sub-processor debugger #203

Closed mrbiggred closed 1 year ago

mrbiggred commented 3 years ago

Fixes #107. For those that don't want the read the really long #107 issue a TL;DR version is below.

When debugging a multi-process server, such as Unicorn or Passenger, inside a Docker container the debugger will hang when it tries to spawn a sub-debugger.

# Output from clicking the RubyMine debug button on Ubuntu 20.04.

/usr/local/bin/docker-compose -f /home/localadmin/Desktop/Repos/myapp/docker-compose.yml -f /home/localadmin/.cache/JetBrains/RubyMine2020.2/tmp/docker-compose.override.11864.yml up --exit-code-from web --abort-on-container-exit web
Starting myapp_db_1_ab4f56db2228 ... 
Recreating myapp_web_1_4ed82856f188 ... 
Attaching to myapp_web_1_4ed82856f188
web_1_4ed82856f188 | Fast Debugger (ruby-debug-ide 0.7.2, debase 0.2.4.1, file filtering is supported) listens on 0.0.0.0:1234
web_1_4ed82856f188 | => Booting Passenger application server
web_1_4ed82856f188 | => Rails 5.2.4.3 application starting in development on http://0.0.0.0:3000
web_1_4ed82856f188 | => Run `rails server -h` for more startup options
web_1_4ed82856f188 | Subprocess Debugger (ruby-debug-ide 0.7.2, debase 0.2.4.1, file filtering is supported) listens on 0.0.0.0:37379

<Hangs on the above line>

This happens even if all the recommended ports are open in:

# docker-compose.yml
services:
  web:
    build: .
    ports:
      - "3000:3000"
      - "1234:1234"
      - "26162:26162"

    <other settings>

The issue occurs because the sub-process uses a random open port but it is unlikely that port is open in your Docker container. My fix was to use a fixed range of ports so you could open them in your Docker config. I choose 58430-58450. If anyone has a better range or thinks 20 ports is too many or too few let me know. I'm also happy to discuss being able to set the sub-process ports dynamically via the command line either in this PR or a future PR.

I wasn't sure the best way to unit test this change. For now I've just removed the mock find_free_port so the tests use the real find_free_port method. If anyone has a better way to test this fix please let me know.

Feedback is much appreciated.

mrbiggred commented 1 year ago

Just a heads up that I created a fork of ruby-debug-ide that fixes the multiport issue on Docker. Please try it out and let me know if it works for you. If you haven any questions, spot an issue, or have an improvement please let me know by opening a issue or PR in the forked repo.