From b539ac1d619c0aafe5988ab8b125a8b43b14d87f Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 30 Oct 2019 09:27:58 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- lib/gitlab/cluster/lifecycle_events.rb | 10 +++++----- lib/gitlab/cluster/mixins/puma_cluster.rb | 6 +++++- lib/gitlab/cluster/mixins/unicorn_http_server.rb | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) (limited to 'lib/gitlab/cluster') diff --git a/lib/gitlab/cluster/lifecycle_events.rb b/lib/gitlab/cluster/lifecycle_events.rb index 294ffad02ce..f931a94938f 100644 --- a/lib/gitlab/cluster/lifecycle_events.rb +++ b/lib/gitlab/cluster/lifecycle_events.rb @@ -33,7 +33,7 @@ module Gitlab # # Sidekiq/Puma Single: This is called immediately. # - # - on_before_phased_restart: + # - on_before_graceful_shutdown: # # Unicorn/Puma Cluster: This will be called before a graceful # shutdown of workers starts happening. @@ -75,9 +75,9 @@ module Gitlab end # Read the config/initializers/cluster_events_before_phased_restart.rb - def on_before_phased_restart(&block) + def on_before_graceful_shutdown(&block) # Defer block execution - (@master_phased_restart ||= []) << block + (@master_graceful_shutdown ||= []) << block end def on_before_master_restart(&block) @@ -108,8 +108,8 @@ module Gitlab end end - def do_before_phased_restart - @master_phased_restart&.each do |block| + def do_before_graceful_shutdown + @master_graceful_shutdown&.each do |block| block.call end end diff --git a/lib/gitlab/cluster/mixins/puma_cluster.rb b/lib/gitlab/cluster/mixins/puma_cluster.rb index e9157d9f1e4..106c2731c07 100644 --- a/lib/gitlab/cluster/mixins/puma_cluster.rb +++ b/lib/gitlab/cluster/mixins/puma_cluster.rb @@ -8,8 +8,12 @@ module Gitlab raise 'missing method Puma::Cluster#stop_workers' unless base.method_defined?(:stop_workers) end + # This looks at internal status of `Puma::Cluster` + # https://github.com/puma/puma/blob/v3.12.1/lib/puma/cluster.rb#L333 def stop_workers - Gitlab::Cluster::LifecycleEvents.do_before_phased_restart + if @status == :stop # rubocop:disable Gitlab/ModuleWithInstanceVariables + Gitlab::Cluster::LifecycleEvents.do_before_graceful_shutdown + end super end diff --git a/lib/gitlab/cluster/mixins/unicorn_http_server.rb b/lib/gitlab/cluster/mixins/unicorn_http_server.rb index 765fd0c2baa..440ed02a355 100644 --- a/lib/gitlab/cluster/mixins/unicorn_http_server.rb +++ b/lib/gitlab/cluster/mixins/unicorn_http_server.rb @@ -5,11 +5,26 @@ module Gitlab module Mixins module UnicornHttpServer def self.prepended(base) - raise 'missing method Unicorn::HttpServer#reexec' unless base.method_defined?(:reexec) + unless base.method_defined?(:reexec) && base.method_defined?(:stop) + raise 'missing method Unicorn::HttpServer#reexec or Unicorn::HttpServer#stop' + end end def reexec - Gitlab::Cluster::LifecycleEvents.do_before_phased_restart + Gitlab::Cluster::LifecycleEvents.do_before_graceful_shutdown + + super + end + + # The stop on non-graceful shutdown is executed twice: + # `#stop(false)` and `#stop`. + # + # The first stop will wipe-out all workers, so we need to check + # the flag and a list of workers + def stop(graceful = true) + if graceful && @workers.any? # rubocop:disable Gitlab/ModuleWithInstanceVariables + Gitlab::Cluster::LifecycleEvents.do_before_graceful_shutdown + end super end -- cgit v1.2.1