Skip to content

Commit 8e838ff

Browse files
authored
Fix shutdown of periodic_updater (#4711)
* Fix shutdown of periodic_updater * current implementation produces "error: can't be called from trap" * Use at_exit hook to shut down periodic_updater * avoids use of sleep commands
1 parent 1723215 commit 8e838ff

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/cloud_controller/runners/puma_runner.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def initialize(config, app, logger, periodic_updater, request_logs)
6262
prometheus_updater.update_gauge_metric(:cc_db_connection_pool_timeouts_total, 0, labels: { process_type: 'main' })
6363
@periodic_updater.setup_updates
6464
end
65+
6566
events.after_stopped do
66-
@periodic_updater.stop_updates unless @periodic_updater.nil?
67+
stop_periodic_updates
6768
end
6869

6970
@puma_launcher = Puma::Launcher.new(puma_config, log_writer:, events:)
@@ -78,6 +79,18 @@ def start!
7879

7980
private
8081

82+
def stop_periodic_updates
83+
@periodic_updater&.stop_updates
84+
@logger.info('Successfully stopped periodic updates in after_stopped')
85+
rescue ThreadError
86+
at_exit do
87+
@periodic_updater&.stop_updates
88+
@logger.info('Successfully stopped periodic updates in at_exit')
89+
end
90+
rescue StandardError => e
91+
@logger.error("Failed to stop periodic updates: #{e}\n#{e.backtrace&.join("\n")}")
92+
end
93+
8194
def prometheus_updater
8295
CloudController::DependencyLocator.instance.prometheus_updater
8396
end

0 commit comments

Comments
 (0)