Fix time zone config not respected in multi-threaded servers
Previously in multi-threaded app servers, such as Puma, the Rails time
zone configuration setting was not being respected. Rails expects the
time zone to be set in application.rb
, and the default value is set in
the active_support.initialize_time_zone
Railtie (https://github.com/rails/rails/blob/d034f488f9c2d694bcad9950df0310ca869956e0/activesupport/lib/active_support/railtie.rb#L42). However, since we
load this setting from a config file, the time zone for GitLab is set
inside an initializer.
Setting Time.zone
in the initializer worked fine with Unicorn, but it
stopped working with Puma. All responses would return timestamps in UTC,
irrespective of the system or Rails time zone. This happened because
Time.zone
calls Thread.current
(https://github.com/rails/rails/blob/161fc87fbf8d0efee2cadc11199fbb4d183ce712/activesupport/lib/active_support/core_ext/time/zones.rb#L15). Since the time zone wasn't set for the
thread, Puma would default to Time.zone_default
, which was UTC.
We now set the default and the Rails configuration settings to be consistent.
Closes #233259 (closed)