Skip to content

Add fixed port range for sub-processor debugger #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

mrbiggred
Copy link

@mrbiggred mrbiggred commented Oct 16, 2020

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.

Now correctly handles StandardError instead of ArgumentError.
Old versions of Ruby not supported by Ruby Build action.
@mrbiggred mrbiggred closed this Sep 13, 2022
@mrbiggred mrbiggred deleted the feature-add-fixed-port-range branch September 13, 2022 22:14
@mrbiggred
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker debugging and sub-debugger with random port
1 participant