puma: systemd socket activation Errno::EBADF: Bad file descriptor - not a socket file descriptor

Steps to reproduce

  1. Follow the instructions here https://github.com/puma/puma/blob/master/docs/systemd.md and create puma.socket and puma.service files for systemd socket activation
  2. After starting the service check its status systemctl status puma.socket puma.service

Expected behavior

Successful start

Actual behavior

● puma.socket - puma accept sockets
   Loaded: loaded (/etc/systemd/system/puma.socket; enabled; vendor preset: enabled)
   Active: failed (Result: service-start-limit-hit) since Wed 2018-01-03 08:59:03 UTC; 3s ago
   Listen: 127.0.0.1:3000 (Stream)

Jan 03 08:58:59  systemd[1]: Listening on puma accept sockets.
Jan 03 08:59:03  systemd[1]: puma.socket: Unit entered failed sta

● puma.service - puma server
   Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2018-01-03 08:59:03 UTC; 3s ago
  Process: 11775 ExecStart=/bin/bash -lci bundle exec puma --config ./config/puma.rb -b tcp:/
 Main PID: 11775 (code=exited, status=1/FAILURE)
      CPU: 581ms

Puma’s log:

Errno::EBADF: Bad file descriptor - not a socket file descriptor
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:65:in `for_fd'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:65:in `block (2 levels) in import_from_env'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:63:in `times'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:63:in `block in import_from_env'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:57:in `each'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:57:in `import_from_env'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/launcher.rb:52:in `initialize'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/cli.rb:68:in `new'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/cli.rb:68:in `initialize'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/bin/puma:8:in `new'
shared/bundle/ruby/2.4.0/gems/puma-3.11.0/bin/puma:8:in `<top (required)>'
shared/bundle/ruby/2.4.0/bin/puma:22:in `load'
shared/bundle/ruby/2.4.0/bin/puma:22:in `<top (required)>'

System configuration

Ruby version: 2.4.1p111 Rails version: 5.1.4 Puma version: 3.11.0

puma.rb

FileUtils.mkdir_p 'tmp/sockets'

threads 1, 16
environment ENV['RAILS_ENV']

Without socket it works just fine

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 36 (27 by maintainers)

Commits related to this issue

Most upvoted comments

Since bundler-v2.3.0, --keep-file-descriptors is the default behaviour (no need to use the flag if your Bundler is recent enough): https://github.com/rubygems/rubygems/issues/3254, https://github.com/rubygems/rubygems/pull/4812

Oh sorry, it looks like I only forgot to add Requires=puma.socket 🙈 Works fine with adding rbenv before and no ExecStop or ExecReload:

ExecStart=/home/user/.rbenv/bin/rbenv exec bundle exec --keep-file-descriptors puma -C ..puma_config_path..

Seems like it’s a configuration issue on our side, there are other people using TCP socket activation fine with Puma 3.12.1, MRI 2.6.2. (https://serverfault.com/questions/960132/puma-with-systemd-and-socket-activation-errnoeaddrinuse)

I’m curious if running this all on Ubuntu 18.04 would fix this for me.