diff --git a/lib/cloud_controller/runners/puma_runner.rb b/lib/cloud_controller/runners/puma_runner.rb index a9e38ad51c..bc436062ed 100644 --- a/lib/cloud_controller/runners/puma_runner.rb +++ b/lib/cloud_controller/runners/puma_runner.rb @@ -62,8 +62,9 @@ def initialize(config, app, logger, periodic_updater, request_logs) prometheus_updater.update_gauge_metric(:cc_db_connection_pool_timeouts_total, 0, labels: { process_type: 'main' }) @periodic_updater.setup_updates end + events.after_stopped do - @periodic_updater.stop_updates unless @periodic_updater.nil? + stop_periodic_updates end @puma_launcher = Puma::Launcher.new(puma_config, log_writer:, events:) @@ -78,6 +79,18 @@ def start! private + def stop_periodic_updates + @periodic_updater&.stop_updates + @logger.info('Successfully stopped periodic updates in after_stopped') + rescue ThreadError + at_exit do + @periodic_updater&.stop_updates + @logger.info('Successfully stopped periodic updates in at_exit') + end + rescue StandardError => e + @logger.error("Failed to stop periodic updates: #{e}\n#{e.backtrace&.join("\n")}") + end + def prometheus_updater CloudController::DependencyLocator.instance.prometheus_updater end