The Rails server doesn't start when trying to bind to a unix socket starting with Puma 3.11.1
1) Add the following to config/puma.rb
bind "unix://tmp/sockets/puma.sock"
pidfile "tmp/pids/puma.pid"
2) run rails s
The rails server should start like below
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.0 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on unix://tmp/sockets/puma.sock
Use Ctrl-C to stop
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.1 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on unix://tmp/sockets/puma.sock
Exiting
.../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/binder.rb:368:in `listen': Address already in use - listen(2) (Errno::EADDRINUSE)
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/binder.rb:368:in `add_unix_listener'
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/binder.rb:141:in `block in parse'
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/binder.rb:88:in `each'
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/binder.rb:88:in `parse'
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/runner.rb:144:in `load_and_bind'
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/single.rb:87:in `run'
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/puma/launcher.rb:183:in `run'
from .../.rvm/gems/ruby-2.4.1/gems/puma-3.11.1/lib/rack/handler/puma.rb:69:in `run'
from .../.rvm/gems/ruby-2.4.1/gems/rack-2.0.4/lib/rack/server.rb:297:in `start'
from .../.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:44:in `start'
from .../.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform'
from .../.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
from .../.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
from .../.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from .../.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from .../.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from .../.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from .../.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from .../.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Ruby version: 2.4.1-p111
Rails version: 5.1.4
Puma version: 3.11.1 and 3.11.2
Using WSL Ubuntu for Win10
Cannot reproduce. Can you confirm tmp/sockets/puma.sock does not exist? $ ls tmp/sockets/.
Sorry, I forgot to say that I am using WSL Ubuntu on Win10. I've edited the original comment
I did a ls tmp/sockets which showed there was an existing socket. Next, I did a rm tmp/sockets/puma.sock. An ls shows the socket is gone. Running rails s gives the original error and leaves the socket file.
I found that I just couldn't get PUMA to run on WSL. There are some known issues with how PUMA wants sockets and I found some mention of an issue with how FORK(2) works (above my head but I got the drift). I had to switch my code to use webricks in development on windows and it started working again.
Using the below config, I was able to get puma listening on a tcp socket and a unix socket
Windows 10 Pro, Version 1709, OS build 16299.192
Puma 3.11.0, ruby 2.4.1-p111
If I do a bundle update to puma 3.11.4, I am able to listen on a tcp socket, but not a unix socket. The socket is created, but I get the Address already in use error as mentioned in a comment above.
We have just experienced this issue too trying to get puma-dev and puma working on WSL Ubuntu. Running puma in the rails project directory boots fine on 0.0.0.0:3000 but using the sock file setup by puma-dev we get exactly the same error as @ryanmk54.
Downgrading from 3.11.4 to 3.11.0 has fixed the problem. Using ruby 2.5.1.
@adampope same problem same solution.
Also same problem with same solution.
Had to downgrade from 3.12.0 to 3.11.0
If everyone in this thread is correct, then the fix for https://github.com/puma/puma/issues/1502 must have caused the issue. Anyone care to confirm?
Needs someone w/WSL to confirm my above comment
Just did some testing under WSL/Ubuntu 18.04. Installed rails and booted a hello world app with no changes and the app comes up, can visit in browser.
Modify config/puma.rb to include:
bind "unix://tmp/sockets/puma.sock"
pidfile "tmp/pids/puma.pid"
Starting with rails s now throws error.
bradland@BRAD1954:~/proj/hello_world$ rails s
/var/lib/gems/2.6.0/gems/railties-6.0.0/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.5-p114), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Exiting
Traceback (most recent call last):
40: from bin/rails:3:in `<main>'
39: from bin/rails:3:in `load'
38: from /home/bradland/proj/hello_world/bin/spring:15:in `<top (required)>'
37: from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
36: from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
35: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
34: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
33: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
32: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
31: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
30: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
29: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
28: from /home/bradland/proj/hello_world/bin/rails:9:in `<top (required)>'
27: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
26: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
25: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
24: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
23: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
22: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
21: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
20: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
19: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
18: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command.rb:46:in `invoke'
17: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command/base.rb:65:in `perform'
16: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
15: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
14: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
13: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `perform'
12: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `tap'
11: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:147:in `block in perform'
10: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:39:in `start'
9: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:297:in `start'
8: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/rack/handler/puma.rb:73:in `run'
7: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/launcher.rb:186:in `run'
6: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/single.rb:98:in `run'
5: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/runner.rb:153:in `load_and_bind'
4: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:90:in `parse'
3: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:90:in `each'
2: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:141:in `block in parse'
1: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:372:in `add_unix_listener'
/home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:372:in `listen': Address already in use - listen(2) (Errno::EADDRINUSE)
Based on the "closed in" commit in #1502 (acb709b), I cracked open vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/minissl.rb and looked for the elsif !data conditional. Found it on L67-L68 of 3.12.1. Commented those two lines out, rm tmp/sockets/puma.sock, and tried rails s again. Got the following trace:
bradland@ BRAD1954:~/proj/hello_world$ bundle exec rails s
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.5-p114), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Exiting
Traceback (most recent call last):
39: from bin/rails:3:in `<main>'
38: from bin/rails:3:in `load'
37: from /home/bradland/proj/hello_world/bin/spring:15:in `<top (required)>'
36: from /home/bradland/proj/hello_world/bin/spring:15:in `require'
35: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
34: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
33: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
32: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
31: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
30: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
29: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
28: from /home/bradland/proj/hello_world/bin/rails:9:in `<top (required)>'
27: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
26: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
25: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
24: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
23: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
22: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
21: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
20: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
19: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
18: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command.rb:46:in `invoke'
17: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command/base.rb:65:in `perform'
16: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
15: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
14: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
13: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `perform'
12: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `tap'
11: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:147:in `block in perform'
10: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:39:in `start'
9: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:297:in `start'
8: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/rack/handler/puma.rb:73:in `run'
7: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/launcher.rb:186:in `run'
6: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/single.rb:98:in `run'
5: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/runner.rb:153:in `load_and_bind'
4: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:90:in `parse'
3: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:90:in `each'
2: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:141:in `block in parse'
1: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:372:in `add_unix_listener'
/home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/binder.rb:372:in `listen': Address already in use - listen(2) (Errno::EADDRINUSE)
So hopefully that's somewhat helpful. I don't really understand the problem, so I'm not able to come up with my own solution paths, but I'm happy to apply diffs to my bundle and test as requested.
@bradland
I there any way for you to check using a more current Puma version?
Sure thing :) Just to be clear, I don't normally develop on WSL/Ubuntu, but I saw Nate make a request on Twitter, so I thought I'd see if I could help out. Was looking to verify this specific case:
If everyone in this thread is correct, then the fix for #1502 must have caused the issue. Anyone care to confirm?
Happy to test further though :)
Using Puma 4.2.1, I get the following trace when running rails s.
bradland@BRAD1954:~/proj/hello_world$ rails s
/var/lib/gems/2.6.0/gems/railties-6.0.0/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.2.1 (ruby 2.6.5-p114), codename: Distant Airhorns
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Exiting
Traceback (most recent call last):
40: from bin/rails:3:in `<main>'
39: from bin/rails:3:in `load'
38: from /home/bradland/proj/hello_world/bin/spring:15:in `<top (required)>'
37: from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
36: from /usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
35: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
34: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
33: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
32: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
31: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
30: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
29: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
28: from /home/bradland/proj/hello_world/bin/rails:9:in `<top (required)>'
27: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
26: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
25: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
24: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
23: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
22: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
21: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
20: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
19: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
18: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command.rb:46:in `invoke'
17: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/command/base.rb:65:in `perform'
16: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
15: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
14: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
13: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `perform'
12: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:138:in `tap'
11: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:147:in `block in perform'
10: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/commands/server/server_command.rb:39:in `start'
9: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:297:in `start'
8: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/rack/handler/puma.rb:73:in `run'
7: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/launcher.rb:172:in `run'
6: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/single.rb:98:in `run'
5: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/runner.rb:154:in `load_and_bind'
4: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/binder.rb:89:in `parse'
3: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/binder.rb:89:in `each'
2: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/binder.rb:150:in `block in parse'
1: from /home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/binder.rb:384:in `add_unix_listener'
/home/bradland/proj/hello_world/vendor/bundle/ruby/2.6.0/gems/puma-4.2.1/lib/puma/binder.rb:384:in `listen': Address already in use - listen(2) (Errno::EADDRINUSE)
Brad,
Thanks. we've got two lines of code that should work:
s = UNIXServer.new(path)
s.listen backlog
Above it was mentioned that 3.11.0 worked, and that used the following two lines:
s = UNIXServer.new(path)
s.listen backlog if backlog
In 3.11.0, backlog defaulted to nil. In 3.11.1, the default was changed to 1024 and the conditional removed.
You could just pick an existing path, add some unused filename, and see if one or the other work in a simple Ruby script. I think the critical thing is whether a call to s.listen works, with or without the backlog argument.
This is working for me (WSL Ubuntu 18.04) on WSL 1
jeremy@A00147 ~/Source/peak [master] $ rails s
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 4.2.1 (ruby 2.5.5-p157), codename: Distant Airhorns
* Min threads: 2, max threads: 2
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
Is this issue a WSL 2 thing? I believe that the networking is not fully functioning in WSL 2.
@AstonDavies
I believe the current issue here is specific to binding to UNIXSockets, not TCP...
Also, all the examples here seem to show single mode. I'd be interested to know if clustered mode works with WSL Ubuntu 18.04. Clustered mode requires fork, which isn't supported on Windows...
Ok, tested it out before I head to lunch. Here's what I've got:
bradland@BRAD1954:~/proj/hello_world$ cat listen.rb
#!/usr/bin/env ruby
require 'socket'
require 'fileutils'
FileUtils.mkdir_p('tmp/sockets/')
path = File.expand_path('tmp/sockets/listen.sock')backlog = 5
s = UNIXServer.new(path)
s.listen backlog
When run, this produces the same Errno:EADDRINUSE exception:
bradland@BRAD1954:~/proj/hello_world$ ./listen.rb
Traceback (most recent call last):
1: from ./listen.rb:11:in `<main>'
./listen.rb:11:in `listen': Address already in use - listen(2) (Errno::EADDRINUSE)
So this may be upstream? A problem with UNIXServer#listen under WSL?
Thanks.
So this may be upstream?
That's what I expected, but just a guess.
If you have a minute, could you try it without the backlog argument, or change:
s.listen backlog
to
s.listen
Sure thing. Tried this:
#!/usr/bin/env ruby
require 'socket'
require 'fileutils'
FileUtils.mkdir_p('tmp/sockets/')
path = File.expand_path('tmp/sockets/listen.sock')
backlog = 5
s = UNIXServer.new(path)
# s.listen backlog
s.listen
Same Errno::EADDRINUSE exception.
Thanks for the testing. Looks like an issue with UNIXSockets & WSL Ubuntu.
One very odd thing.
If you look at the doc's for UNIXServer#listen, which is inherited from Socket#listen, you'll see that the error Errno::EADDRINUSE is listed as a Windows specific error. Interesting...
Closing as upstream, but does anyone know a useful place for us to report this?
I'm seeking answers in #ruby on IRC. Encapsulated a reproduction script in this gist: https://gist.github.com/bradland/203aa0d1869db04d828eaa9360e0be5b. I have a feeling this will end up in the Ruby Redmine bug tracker, but hopefully will get confirmation.
Opened an issue with ruby-lang.org: https://bugs.ruby-lang.org/issues/16277.
JFYI, it very well may get flagged as 'Third Party'. Filing an issue at
https://github.com/microsoft/WSL
might be better, but I'm not much of a c type. Thanks, Greg
Yeah, good possibility there. I figured I'd run it past Ruby-lang first so they can see if the exception is being raised by some bug internal to the socket lib, or if it's actually coming from the OS. I'm not a c type either, but hopefully they can get me enough details to run it over to microsoft/WSL :)
@bradland
I posted in ruby-lang, but the following (with additional code changes) works in Puma, replacing the UNIXServer code:
require 'socket'
backlog = 1024
path = 'tmp.sock'
sock = Socket.new :UNIX, :STREAM
sock.bind Addrinfo.unix(path, :STREAM)
sock.listen backlog
As noted by the response there, UNIXServer#new also calls listen, and (obviously) calling it again may throw an error in some OS's.
Most helpful comment
Thanks for the testing. Looks like an issue with UNIXSockets & WSL Ubuntu.
One very odd thing.
If you look at the doc's for
UNIXServer#listen, which is inherited fromSocket#listen, you'll see that the errorErrno::EADDRINUSEis listed as a Windows specific error. Interesting...