From f0c52df5e540e825be0babd04cc557f3f40cf1c6 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 28 Feb 2019 23:25:37 +0000 Subject: sidekiq: terminate child processes at shutdown Sidekiq jobs frequently spawn long-lived child processes to do work. In some circumstances, these can be reparented to init when sidekiq is terminated, leading to duplication of work and strange concurrency problems. This commit changes sidekiq so that, if run as a process group leader, it will forward `INT` and `TERM` signals to the whole process group. If the memory killer is active, it will also use the process group when resorting to `kill -9` to shut down. These changes mean that a naive `kill ` will now do the right thing, killing any child processes spawned by sidekiq, as long as the process supervisor placed it in its own process group. If sidekiq isn't a process group leader, this new code is skipped. --- config/initializers/sidekiq.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'config') diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 4a8d72e37a5..2e4aa9c1053 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -77,6 +77,9 @@ Sidekiq.configure_server do |config| # Avoid autoload issue such as 'Mail::Parsers::AddressStruct' # https://github.com/mikel/mail/issues/912#issuecomment-214850355 Mail.eager_autoload! + + # Ensure the whole process group is terminated if possible + Gitlab::SidekiqSignals.install!(Sidekiq::CLI::SIGNAL_HANDLERS) end Sidekiq.configure_client do |config| -- cgit v1.2.1