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

RubyMine and Docker integration seems buggy #158

Closed lancedikson closed 5 years ago

lancedikson commented 5 years ago

Trying to run a Rails test in debug mode with RubyMine, running it on Docker and it doesn't work for some reason. Normal mode works fine though. Does anybody have an idea what's wrong with the debug mode here?

Testing started at 17:04 ...
/usr/local/bin/docker-compose -f /Users/lancedikson/RubymineProjects/videoly-app/docker-compose.yml -f /Users/lancedikson/Library/Caches/RubyMine2018.2/tmp/docker-compose.override.11.yml up --exit-code-from web --abort-on-container-exit web
Starting videoly-app_rubymine_helpers_1 ... 
videoly-app_db_1 is up-to-date
Starting videoly-app_web_1              ... 
Attaching to videoly-app_web_1
web_1               | Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:1234
web_1               | Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:33039
web_1               | 9: connection failed(1)
web_1               | Exception: Connection refused - connect(2) for "172.20.0.1" port 26168
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `initialize'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `open'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `block in notify_dispatcher'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `times'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `notify_dispatcher'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:116:in `block in start_control'
web_1               | 9: connection failed(2)
web_1               | Exception: Connection refused - connect(2) for "172.20.0.1" port 26168
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `initialize'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `open'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `block in notify_dispatcher'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `times'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `notify_dispatcher'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:116:in `block in start_control'
web_1               | 9: connection failed(3)
web_1               | Exception: Connection refused - connect(2) for "172.20.0.1" port 26168
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `initialize'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `open'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `block in notify_dispatcher'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `times'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `notify_dispatcher'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:116:in `block in start_control'
lancedikson commented 5 years ago

Ok, I provided really few words since I thought, that maybe somebody encountered the error already. I was trying to run tests in debug mode using RubyMine. It doesn't seem working for some reason. I tried to investigate the reason of that, and checkouted this repo: https://github.com/GabLeRoux/rails-docker-compose-rubymine-example just to check if it works with someones configuration. So, yes, it works with Ruby 2.2.4 and Rails 4.2, but it doesn't seem working with Ruby 2.5.0 and Rails 5.2.0.

lancedikson commented 5 years ago

I tried to update debase and ruby-debug-ide until the last available beta versions and the test seems running in debug mode now (before they were stuck on the last exception), but with exceptions still:

Testing started at 01:41 ...
/usr/local/bin/docker-compose -f /Users/lancedikson/RubymineProjects/videoly-app/docker-compose.yml -f /Users/lancedikson/Library/Caches/RubyMine2018.2/tmp/docker-compose.override.239.yml up --exit-code-from web --abort-on-container-exit web
Starting videoly-app_rubymine_helpers_1 ... 
videoly-app_db_1 is up-to-date
Recreating videoly-app_web_1            ... 
Attaching to videoly-app_web_1
web_1               | Fast Debugger (ruby-debug-ide 0.7.0.beta6, debase 0.2.3.beta2, file filtering is supported) listens on 0.0.0.0:1234
web_1               | 9: connection failed(1)
web_1               | Exception: Connection refused - connect(2) for "172.20.0.1" port 26168
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `initialize'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `open'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `block in notify_dispatcher_if_needed'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:166:in `times'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:166:in `notify_dispatcher_if_needed'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:123:in `block in start_control'
web_1               | 9: connection failed(2)
web_1               | Exception: Connection refused - connect(2) for "172.20.0.1" port 26168
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `initialize'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `open'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `block in notify_dispatcher_if_needed'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:166:in `times'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:166:in `notify_dispatcher_if_needed'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:123:in `block in start_control'
web_1               | 9: connection failed(3)
web_1               | Exception: Connection refused - connect(2) for "172.20.0.1" port 26168
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `initialize'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `open'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:168:in `block in notify_dispatcher_if_needed'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:166:in `times'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:166:in `notify_dispatcher_if_needed'
web_1               |   /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:123:in `block in start_control'
web_1               | Fatal exception in DebugThread loop: undefined method `accept' for 3:Integer
web_1               | Backtrace:
web_1               | /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta6/lib/ruby-debug-ide.rb:131:in `block in start_control'
web_1               | Started
web_1               | 
web_1               | 
web_1               | 
web_1               | web_1               | 
web_1               | web_1               | 
web_1               | web_1               | works
web_1               | 
web_1               | web_1               | 
web_1               | web_1               | Finished in 4.90954s
web_1               | 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
videoly-app_web_1 exited with code 0
Aborting on container exit...

Process finished with exit code 0
lancedikson commented 5 years ago

Tried running ruby 2.4.4 instead of 2.5.0. Didn't work. Seems like the reason is in the specific operation and Rails 5.2.0 (since it worked with Rails 4.2.0, as I mentioned above)

ViugiNick commented 5 years ago

@lancedikson Do you have 26168 port opened?

lancedikson commented 5 years ago

@ViugiNick, hey, I'm not sure if it was. But I already left the use of Docker runtime for development. It's much faster when it's running on the real machine. Basically, I can't reproduce the issue anymore. Thus we can close this until somebody run into the same problem.

tuckerbuchy commented 5 years ago

@lancedikson Just ran into this while trying to do local environment setup using docker-compose

stat-hq      | *** resque-1.25.2: Forked 770 at 1547680179
stat-hq      | Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:43259
stat-hq      | 770: connection failed(1)
stat-hq      | Exception: Connection refused - connect(2) for "192.168.128.1" port 26168
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `initialize'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `open'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `block in notify_dispatcher'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `times'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `notify_dispatcher'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:116:in `block in start_control'
stat-hq      | 770: connection failed(2)
stat-hq      | Exception: Connection refused - connect(2) for "192.168.128.1" port 26168
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `initialize'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `open'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `block in notify_dispatcher'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `times'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `notify_dispatcher'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:116:in `block in start_control'
stat-hq      | 770: connection failed(3)
stat-hq      | Exception: Connection refused - connect(2) for "192.168.128.1" port 26168
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `initialize'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `open'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:153:in `block in notify_dispatcher'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `times'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:151:in `notify_dispatcher'
stat-hq      |  /usr/local/bundle/gems/ruby-debug-ide-0.6.1/lib/ruby-debug-ide.rb:116:in `block in start_control'
cesar3030 commented 5 years ago

@tuckerbuchy I'm getting the exact same error. Did you find a way to solve this issue? I'm using:

Thanks :)

ViugiNick commented 5 years ago

@cesar3030 @tuckerbuchy Looks like you are using pretty old ruby-debug-ide and debase versions

cesar3030 commented 5 years ago

Thanks @ViugiNick! I changed my Gemfile to force using these versions:

gem 'ruby-debug-ide', '0.7.0.beta7'
gem 'debase', '0.2.3.beta3'

I know it's not the best to use beta versions but it does the job for now 👍

arthur5005 commented 5 years ago

Installed the latest version of ruby-debug-ide and debase and I can't make the connection myself: Rails: 5.0.7 Ruby 2.4.5

screen shot 2019-02-01 at 1 13 39 pm screen shot 2019-02-01 at 1 15 01 pm
cesar3030 commented 5 years ago

I had the same issue with RubyMine when trying to run Rspec tests in debug mode. Since It was working with VSC so I choose to go ahead and start using VSC instead of RubyMine (at least while this issue has not been solved)...

ViugiNick commented 5 years ago

@cesar3030 @arthur5005 So VSC debug works with the same ports?

Maybe it will help https://github.com/ruby-debug/ruby-debug-ide/issues/107#issuecomment-459452023

cesar3030 commented 5 years ago

This is what I did to debug in VSC. It's a bit of a hack but it does the job for now...

Every time I need to debug, I've to set the RDEBUG env variable to:

docker-compose.yml:

 web:
    build: .
    environment:
      RDEBUG: ''
    command: sh scripts/start.sh
    volumes:
      - .:/app
    ports:
      - 3000:3000
      - 1234:1234
      - 26162:26162

My start script:

rm -f tmp/pids/server.pid 

if [ "${RDEBUG}" = "rails" ] ;then
  bundle exec rdebug-ide --debug --host 0.0.0.0 --port 1234 -- bin/rails s -p 3000 -b 0.0.0.0
elif [ "${RDEBUG}" = "rspec" ] ;then
  bundle exec rdebug-ide --debug --host 0.0.0.0 --port 1234 -- bin/bundle exec rspec spec
else 
  bundle exec rails s -p 3000 -b 0.0.0.0
fi

Here is my attach to docker VSC Config:

{
      "name": "Attach to Docker",
      "type": "Ruby",
      "request": "attach",
      "remotePort": "1234",
      "remoteHost": "127.0.0.1",
      "remoteWorkspaceRoot": "/app",
      "cwd": "${workspaceRoot}",
      "showDebuggerOutput": true
}

Step to debug:

This is a lot of steps and I wish I will find a better way to debug asap.

ViugiNick commented 5 years ago

@cesar3030 @arthur5005 Could you try to install ruby-debug-ide gem from this branch https://github.com/ViugiNick/ruby-debug-ide/tree/so_reuseport. It should use only one port for debugging and one --dispatcher port

cesar3030 commented 5 years ago

I will try it next time I'll have to debug my rails app.

arthur5005 commented 5 years ago

@ViugiNick I just had a moment to try that branch today. Still failing, with connection refused.

Exception: Connection refused - connect(2) for "172.19.0.1" port 26168
masterfox_1      |  /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:168:in `initialize'
masterfox_1      |  /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:168:in `open'
masterfox_1      |  /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:168:in `block in notify_dispatcher_if_needed'
masterfox_1      |  /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:166:in `times'
masterfox_1      |  /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:166:in `notify_dispatcher_if_needed'
masterfox_1      |  /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:123:in `block in start_control'
masterfox_1      | Fatal exception in DebugThread loop: undefined method `accept' for 3:Integer
masterfox_1      | Backtrace:
masterfox_1      | /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:131:in `block in start_control'
masterfox_1      | 507: connection failed(1)
howtwizer commented 5 years ago

Have save issue. Running thought docker-compose.yml Exception: Connection refused - connect(2) for "172.27.0.1" port 26168

MuhmdRaouf commented 5 years ago

i am having the same issue and also i had nothing showing in my browser, here's the error log:

rails_1    | Fast Debugger (ruby-debug-ide 0.7.0.beta7, debase 0.2.3.beta5, file filtering is supported) listens on 0.0.0.0:1234
rails_1    | Array values in the parameter to `Gem.paths=` are deprecated.
rails_1    | Please use a String or nil.
rails_1    | An Array ({"GEM_PATH"=>["/usr/local/bundle", "/root/.gem/ruby/2.3.0", "/usr/local/lib/ruby/gems/2.3.0"]}) was passed in from /opt/code/bin/rails:3:in `load'
rails_1    | WARNING: You are running Ruby 2.3.1, which is nearing end-of-life.
rails_1    | The Google Cloud API clients work best on supported versions of Ruby. Consider upgrading to Ruby 2.4 or later.
rails_1    | See https://www.ruby-lang.org/en/downloads/branches/ for more info on the Ruby maintenance schedule.
rails_1    | To suppress this message, set the GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable.
rails_1    | DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from <top (required)> at /opt/code/config/application.rb:8)
rails_1    | RAILS_ENV = development
rails_1    | RACK_ENV = development
rails_1    | => Booting Puma
rails_1    | => Rails 4.2.4 application starting in development on http://0.0.0.0:3000
rails_1    | => Run `rails server -h` for more startup options
rails_1    | => Ctrl-C to shutdown server
rails_1    | getting all language from AWS S3 ["ar", "backup/", "backup/en_2019_01_07", "en", "enabled/", "enabled/en", "enabled/en_1_0", "enabled/he", "enabled/he_1_0", "enabled/he_1_1", "fr", "he"][15] Puma starting in cluster mode...
rails_1    | [15] * Version 3.12.0 (ruby 2.3.1-p112), codename: Llamas in Pajamas
rails_1    | [15] * Min threads: 5, max threads: 5
rails_1    | [15] * Environment: development
rails_1    | [15] * Process workers: 2
rails_1    | [15] * Preloading application
rails_1    | [15] * Listening on tcp://0.0.0.0:3000
rails_1    | [15] Use Ctrl-C to stop
rails_1    | 20: connection failed(1)23: connection failed(1)
rails_1    | Exception: Connection refused - connect(2) for "172.19.0.1" port 26168
rails_1    |    /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:168:in `initialize'
rails_1    |    /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:168:in `open'
rails_1    |    /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:168:in `block in notify_dispatcher_if_needed'
rails_1    |    /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:166:in `times'
rails_1    |    /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:166:in `notify_dispatcher_if_needed'
rails_1    |    /usr/local/bundle/gems/ruby-debug-ide-0.7.0.beta7/lib/ruby-debug-ide.rb:123:in `block in start_control'
eric-eye commented 5 years ago

RubyMine users: I also got very blocked on the Connection refused problem when trying to use this for rspec. The only apparent trigger was attempting to debug my Rails web app, and after that, I absolutely could not get it to work again.

I can't reason as to why, but disabling Spring for debugging helped me out here. I'd previously had the forked Spring config for the project, but I removed this and allowed RubyMine to disable it for the project, and voila, no more errors.

However, I am still having trouble getting it to work for running the Rails application.

ViugiNick commented 5 years ago

@eiseneker Maybe you need to forward more ports with enabled spring

wheelq commented 4 years ago

any luck?

Greyvend commented 4 years ago

Same problem, running rails server via debugger works fine but debugging tests fails with "Connection refused".

dhanaraj-ally commented 3 years ago

I am having the same issue, anyone sorted this out?

Rory-Powell commented 3 years ago

+1 same issue here

Exception: Connection refused - connect(2) for "172.26.0.1" port 26168

running through interpreter configured via docker compose

hurricup commented 3 years ago

@Rory-Powell please, use rubymine tracker to report issues about rubymine.

dhanaraj-ally commented 3 years ago

@Rory-Powell Please take a look at this comment (https://github.com/ruby-debug/ruby-debug-ide/issues/107#issuecomment-709986800). Issue https://github.com/ruby-debug/ruby-debug-ide/issues/107

I have worked around this issue & issue reported in #107 using fixes discussed in respective issues. Since changes are not merged to release, I'm using a different branch with the fix.

Rory-Powell commented 3 years ago

Update: The cause in my case was puma running in clustered mode. When running in single mode the connection works just fine.

I noticed that a single connection attempt is made in single mode where as two connections are attempted in clustered mode and the second one is where the exception is being raised.

rgavriel commented 1 year ago

Yes, the issue only happen when trying to run in clustered mode, but what if I need to run in clustered mode?

anhtn2 commented 1 year ago

Update: The cause in my case was puma running in clustered mode. When running in single mode the connection works just fine.

I noticed that a single connection attempt is made in single mode where as two connections are attempted in clustered mode and the second one is where the exception is being raised.

@Rory-Powell you saved my life

MuhmdRaouf commented 1 year ago

Has anyone managed to get it working in clustered mode yet?

zethembisogwala commented 10 months ago

if anyone hasn't managed to fix this yet, just ensure the dispatcher port is not included in your docker compose file port mappings, unlike suggested on the readme of this gem

pbourdet commented 9 months ago

Update: The cause in my case was puma running in clustered mode. When running in single mode the connection works just fine.

I noticed that a single connection attempt is made in single mode where as two connections are attempted in clustered mode and the second one is where the exception is being raised.

This is the only thing that worked for me

Thanks @Rory-Powell ❤️