Skip to content
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

Bad file descriptor (Errno::EBADF) server restart crash on ruby 2.0.0preview2 #177

Closed
masterkain opened this issue Dec 25, 2012 · 12 comments · Fixed by #220
Closed

Bad file descriptor (Errno::EBADF) server restart crash on ruby 2.0.0preview2 #177

masterkain opened this issue Dec 25, 2012 · 12 comments · Fixed by #220

Comments

@masterkain
Copy link

I'm playing around with puma on OS X 10.8.2 and tried to issue a restart through the web api using 1.6.3 started with:

bundle exec puma -p $PORT --control tcp://127.0.0.1:9293 --control-token foo

results in:

* Restarting...
Puma 1.6.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Inherited tcp://0.0.0.0:5000
/Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/gems/puma-1.6.3/lib/puma/server.rb:128:in `for_fd': Bad file descriptor (Errno::EBADF)
 from /Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/gems/puma-1.6.3/lib/puma/server.rb:128:in `inherit_tcp_listener'
 from /Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/gems/puma-1.6.3/lib/puma/cli.rb:320:in `block in run'
 from /Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/gems/puma-1.6.3/lib/puma/cli.rb:314:in `each'
 from /Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/gems/puma-1.6.3/lib/puma/cli.rb:314:in `run'
 from /Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/gems/puma-1.6.3/bin/puma:10:in `<top (required)>'
 from /Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/bin/puma:19:in `load'
 from /Users/kain/.rvm/gems/ruby-2.0.0-preview2@mygemset/bin/puma:19:in `<main>'

Update: same error on Master.

@gregmolnar
Copy link

I have a similar issue on Ubuntu with master and ruby 2.0.0.p0. I am using a socket instead of a tcp port so my error is

/.../shared/bundle/ruby/2.0.0/bundler/gems/puma-2e2440024623/lib/puma/binder.rb:246:in `for_fd': Bad file descriptor (Errno::EBADF)
from /.../shared/bundle/ruby/2.0.0/bundler/gems/puma-2e2440024623/lib/puma/binder.rb:246:in `inherit_unix_listener'
from /.../shared/bundle/ruby/2.0

@brentkirby
Copy link

+1 on this, same exact message as masterkain above, but using sockets

@evanphx
Copy link
Member

evanphx commented Mar 18, 2013

Seems #220 has solved this. I didn't realize ruby 2.0 changed this behavior.

@evanphx evanphx closed this as completed Mar 18, 2013
@alindeman
Copy link

Can you release a version to rubygems.org with this fix?

@flackou
Copy link

flackou commented Apr 19, 2013

+1 (using TCP port, not socket)

@adamdilek
Copy link

adamdilek commented Jul 30, 2016

is it fixed ?
I'm getting following error on ubuntu for production

bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``': Bad file descriptor (Errno::EBADF)

@evanphx
Copy link
Member

evanphx commented Jul 30, 2016

The puma issue is long fixed. That's something wrong with your OS probably.
On Sat, Jul 30, 2016 at 6:51 AM Muhammet notifications@github.com wrote:

is it fixed ?
I'm getting following error

bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``': Bad file descriptor (Errno::EBADF)


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#177 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAAB-O9zYNlVP7f73-_DsrdkyLLpCgYks5qa1bOgaJpZM4AVIXO
.

@joeczucha
Copy link

joeczucha commented Aug 8, 2016

If anyone else comes here searching for a solution to the above

/home/deploy/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``': Bad file descriptor (Errno::EBADF)

It was being caused on my system by me having missed out a comma in the stdout_redirect line.

i.e.

stdout_redirect "#{root}/shared/log/puma.log" "#{root}/shared/log/puma_error.log"

in my config/puma.rb, file when it should be:

stdout_redirect "#{root}/shared/log/puma.log", "#{root}/shared/log/puma_error.log"

Hope this helps someone :)

@Gaolz
Copy link

Gaolz commented Sep 29, 2016

@joeczucha Thanks so much, Your answer solves my problem.

@revathskumar
Copy link

@joeczucha Thanks, For me it was log folder which was missing.

@straight-shoota
Copy link

I stumbled upon the same error as @muhammet and @joeczucha and @revathkumar, but it's neither a missing comma nor log folder. And the error message was really not helping in any way :/

Full log output:

[17434] Puma starting in cluster mode...
[17434] * Version 3.6.2 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
[17434] * Min threads: 0, max threads: 16
[17434] * Environment: production
[17434] * Process workers: 1
[17434] * Preloading application
[17434] * Listening on tcp://0.0.0.0:0
[17434] * Listening on unix:///data/web/kath-cms/shared/puma.sock
[17434] Use Ctrl-C to stop
/home/kathmin/.gem/ruby/2.3.1/gems/activesupport-5.0.1/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``': Bad file descriptor (Errno::EBADF)
        from /home/kathmin/.gem/ruby/2.3.1/gems/activesupport-5.0.1/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/source/git/git_proxy.rb:161:in `block (2 levels) in git'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/source/git/git_proxy.rb:233:in `block in capture_and_filter_stderr'
        from /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/tempfile.rb:295:in `open'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/source/git/git_proxy.rb:231:in `capture_and_filter_stderr'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/source/git/git_proxy.rb:161:in `block in git'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/shared_helpers.rb:72:in `with_clean_git_env'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/source/git/git_proxy.rb:160:in `git'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/source/git/git_proxy.rb:88:in `full_version'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/env.rb:78:in `git_version'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/env.rb:22:in `report'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/friendly_errors.rb:74:in `request_issue_report_for'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/friendly_errors.rb:40:in `log_error'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/friendly_errors.rb:102:in `rescue in with_friendly_errors'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
        from /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/exe/bundle:26:in `<top (required)>'
        from /opt/rubies/ruby-2.3.1/bin/bundle:23:in `load'
        from /opt/rubies/ruby-2.3.1/bin/bundle:23:in `<main>'

puma config:

#!/usr/bin/env puma
# Ansible managed

environment ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'production'

shared = "/data/web/kath-cms/shared"

directory "/data/web/kath-cms"
rackup "/data/web/kath-cms/current/config.ru"
pidfile "#{shared}/puma.pid"
state_path "#{shared}/puma.state"
activate_control_app "unix://#{shared}/pumactl.sock", { no_token: true }

port 0
bind "unix://#{shared}/puma.sock"

preload_app!

workers Integer(ENV['PUMA_WORKERS'] || 1)
threads Integer(ENV['MIN_THREADS']  || 0), Integer(ENV['MAX_THREADS'] || 16)

stdout_redirect '/data/web/kath-cms/logs/puma.log', '/data/web/kath-cms/logs/puma.error.log', true

on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = "/data/web/kath-cms/current/Gemfile"
end

on_worker_boot do
  ActiveSupport.on_load(:active_record) do
    ActiveRecord::Base.establish_connection
  end
end

# Allow puma to be restarted by touching tmp/restart.txt
plugin :tmp_restart if respond_to? :plugin # if an app is running an older version of puma

The reason was: The log files were not writable for the executing user. I missed this at first, because the log files are symlinked.

It would be nice if puma could offer a meaningful error message that could actually assist in solving a problem.

@0x64696d61
Copy link

  1. Add to deploy.rb
    set :puma_restart_command, 'bundle exec --keep-file-descriptors puma'
  2. Update puma config on server
    cap puma:config

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 a pull request may close this issue.