Skip to content

Instantly share code, notes, and snippets.

@tskogberg
Created April 11, 2017 07:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tskogberg/c7cbd42008f8ec8fd920817a2229cf33 to your computer and use it in GitHub Desktop.
Save tskogberg/c7cbd42008f8ec8fd920817a2229cf33 to your computer and use it in GitHub Desktop.
Heroku: Fix "SignalException: SIGHUP" errors
#!/usr/bin/env ruby
APP_PATH = File.expand_path("../../config/application", __FILE__)
require_relative "../config/boot"
# Make a clean exit on Heroku while running a rails console.
# Without this we'll get a "SignalException: SIGHUP" error in honeybadger.
if ENV["DYNO"]
if ["c", "console"].include?(ARGV.first)
Signal.trap("SIGHUP") { exit 0 }
end
end
require "rails/commands"
@taylorbrooks
Copy link

@tskogberg Where did you put this code? In an initializer?

@MarinaMurashev
Copy link

@taylorbrooks i think this goes into bin/rails

@MarinaMurashev
Copy link

@tskogberg thank you for this script, I just used it and worked like a charm! 👏

@saferodrigo
Copy link

this works only with heroku?

@henrik
Copy link

henrik commented Feb 8, 2022

I work with @tskogberg and can confirm we've put this in bin/rails. Our current bin/rails with Rails 5.2 is

#!/usr/bin/env ruby
begin
  load File.expand_path("../spring", __FILE__)
rescue LoadError => e
  raise unless e.message.include?("spring")
end

followed by the code above (except for its hashbang).

We've only tried this with Heroku but it may work on other platforms if they set ENV["DYNO"] and work in a similar way. Please write a comment if you try it.

@SimBed
Copy link

SimBed commented Jan 18, 2024

I implemented this piece of code in July 2023 on a Rails 6 app (in bin/rails as suggested). It worked nicely. No more errors. But after some time the errors returned. I can see I upgraded to Rails 7 in August 2023 and around this time the errors returned. Possibly related?

I just checked again today:
Rails 7 app, fix code as shown above, implemented in bin/rails
$heroku run rails c
(left alone for 1 hour)
irb(main):001:0> Error: timed out
$heroku logs
...Process exited with status 129
and HoneyBadger reported a SignalException: SIGHUP error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment