Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.9.9]

### Fixed
- Exit cleanly on SIGTERM received during application boot, before the runner installs its graceful signal handling, so a shutdown mid-boot is no longer reported as a crash

## [1.9.8]

- Improve performance by reusing SNS client
Expand Down
11 changes: 11 additions & 0 deletions lib/eventboss/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def parse(args = ARGV)
end

def run
setup_boot_signal_traps

boot_system

Eventboss.logger.info('Starting eventboss...')
Expand All @@ -39,6 +41,15 @@ def run

private

# Booting the application (e.g. loading Rails) can take long enough that a
# termination signal arrives before Runner installs its graceful signal
# handling. Without a handler the process dies non-gracefully and is
# reported as a crash. Until Runner takes over, exit cleanly on SIGTERM so
# a shutdown mid-boot is not treated as a failure.
def setup_boot_signal_traps
Signal.trap('SIGTERM') { exit 0 }
end

def boot_system
require 'rails'
if ::Rails::VERSION::MAJOR < 4
Expand Down
2 changes: 1 addition & 1 deletion lib/eventboss/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Eventboss
VERSION = "1.9.8"
VERSION = "1.9.9"
end
29 changes: 29 additions & 0 deletions spec/eventboss/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,34 @@
expect { subject.run }.to raise_error LoadError
end
end

describe 'when SIGTERM is received during boot' do
let(:default_sigterm_signal) { Signal.trap 'SIGTERM', 'SYSTEM_DEFAULT' }

after { Signal.trap 'SIGTERM', default_sigterm_signal }

it 'exits with status 0 instead of crashing' do
reader, writer = IO.pipe

pid = fork do
reader.close
allow(subject).to receive(:boot_system) do
writer.puts 'booting'
sleep 5
end
allow(Eventboss).to receive(:launch)

subject.run
end

writer.close
reader.gets

Process.kill 'SIGTERM', pid
_, status = Process.wait2(pid)

expect(status.exitstatus).to eq 0
end
end
end
end