Failed to find free socket port for process dispatcher

Answered

My scenario is pretty much this one.

There's a Docker Compose running rails with:

ports:
- "3000:3000"
- "1234:1234"
- "26162:26162"

With gems:

Using debase 0.2.2.beta10
Using ruby-debug-ide 0.6.1

The command:

bundle exec rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- \
/app/bin/rails server -b 0.0.0.0 -p 3000 -e development'

That yelds:

Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2.beta10, file filtering is supported) listens on 0.0.0.0:1234

The configuration for remote debug on RubyMine:

Remote host: 127.0.0.1
Remote port: 1234
Remote root folder: /app
Local port: 26162
Local root folder: /path/to/src

The result of Ctrl+Shift+F9:

Error running 'develop': Failed to find free socket port for process dispatcher

The very same configuration on VSCode just works flawlessly:

{
"version": "0.2.0",
"configurations": [
{
"name": "rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}/src",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "/app"
},
]
}

This is frustrating.

7
17 comments

I had the same problem but it has been resolved by removing the setting `- "26162:26162"` of `ports` .
My understanding is:
* The port is supposed to be used by the IDE, not by rdebug-ide.
* But the port is busy because Docker uses it based on the binding settings.
* Removing it frees the port.

2

This is a problem with a Rack application:

  • RubyMine: 2020.1.3
  • Windows 10: 1909 (OS Build 18363.959)
  • Docker Desktop: 2.3.0.3 (45519)
  • Docker: 19.03.8, build afacb8b
  • Docker Compose: 1.25.5, build 8a1c60f6
  • Ruby Image: ruby:2.6.6
  • Gems:
    -puma: 4.3.5
    - rack: 2.2.3
    - debase:0.2.4.1
    - ruby-debug-ide: 0.7.2

But works in Visual Studio Code.

 

1

RUBY-25140 seems different from the problem I reported.  I get this

 

using this docker-compose.yml

version: "3.8"
services:
app:
build:
context: .
args:
APP_ROOT: /usr/src/app/
volumes:
- .:/usr/src/app/
ports:
- "9292:9292"
- "1234:1234"
- "26162:26162"
working_dir: /usr/src/app/
command: rdebug-ide --debug --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- /usr/local/bundle/bin/rackup --port 9292 --host 0.0.0.0


And this Ruby remote debug:



1

Takc923 Thank you so much for you comment, it was exactly what I did to get the things working, I did everything but this specific step.

It was the command I am running

bundle exec rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s -p 3000 -b 0.0.0.0

This is the docker-compose ports configuration

ports:
- "3000:3000"
- "1234:1234"

Awesome.

 

 

1
Avatar
Permanently deleted user

I'm running into the same scenario. If I launch my app without docker, my remote debugger can connect fine. But when I launch with Docker, it runs into the "failed to find... port..." error. I have the correct ports opened up in my docker compose file like so:

command: sh -c 'rm -rf ./tmp && bundle exec rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s -b 0.0.0.0'
ports:
- 3000:3000
- 1234:1234
- 26162:26162
0

Hello,

it's possible to add docker-compose Ruby SDK and launch debugging session using it (that is, without remote debug). Have you tried that?

0
Avatar
Permanently deleted user

I'll try to experiment with that some time (sorry for not giving it a shot right now).

I was able to track this down - https://github.com/ruby-debug/ruby-debug-ide/issues/107 It seems that something around the combination of docker and Rubymine causes a random port (in the ephemeral range, I think) to be used for the actual debugging, but the docker container doesn't have that port opened. Without digging into it further, I can't say whether the issue is with that gem or with Rubymine, but it looks like the gem maintainers are trying to implement a workaround/fix.

0
Avatar
Permanently deleted user

Same exact issue for me with PyCharm.  I have to start the app then start the server (container).  If I want to restart the app then I need to stop the container before restarting the app.

0

Are there any updates on this issue?

 

I've never been able to attach a debugger because of this and this is the only reason why I'd want to use RubyMine. This works perfectly fine with VS Code like others have mentioned, so it is something that can be fixed on RubyMine

0

Same problem in RubyMine: 2020.1.4.

0

In case there's an issue with connecting to Docker in PyCharm it'd be better to submit an issue on its tracker

As for RubyMine, there's a similar issue regarding ports so could you please check it: https://youtrack.jetbrains.com/issue/RUBY-25140 If it's not the case then a project sample with steps for reproduce would be great. You can also check whether it works for you with our sample app

0

Thanks for the response Olga!

When I try to follow all instructions in the sample app you provided, I got the following error:

Webpacker::Manifest::MissingEntryError in StaticPages#home

Showing /sample_rails_application/app/views/layouts/application.html.erb where line #12 raised:

Webpacker can't find application in /sample_rails_application/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
Also, if I attempt to follow a similar setup to that app in my project, I get a 'Error running "Development: app": Index 0 out of bounds for length 0'.I think this more closely resembles this reported issue: https://youtrack.jetbrains.com/issue/RUBY-25110

0

Oh also on the sample application I am seeing the following error in the logs: `Exception: Connection refused - connect(2) for "172.30.0.1" port 26168`

0

This also fails for RubyMine 2020.2 BETA

0

Hi Lnorth - this probably won't change anything for you, but you misspelled your Remote root folder. Looks like it should be /usr/src/app

Please keep this thread updated if you figure anything else out. This has been frustrating me for months because I want to debug in docker and have not been able to yet. I can in VS Code but then they don't have the "Ignore non-project files" option on the debugger so nothing is ideal right now.

0

Socketman, Thanks for the correction.  Same result after fixing the remote root.

 

0

I found a solution that worked resolved this issue for me.   The solution was to place my docker-compose.yml file within the rails app directory.  I had mine located at a directory above it and it worked when I moved it to the rails directory. I had my project configured as multi-module application, however, the debugger only worked when I had Intellij configured as a rails project at the root level.  Also, I opened intellij from the docker app.  In docker desktop app, you can see your container is running then hover over it and you'll see a 'open in Intellij' button.  If you click this button it should bring you to the rails app.  From here all I needed to do was add the remote ruby SDK configuration to the project, wait for it to do update indexes, then I was good to run the debugger.   

0

Please sign in to leave a comment.