Commit e9c8fde0 authored by Stan Hu's avatar Stan Hu

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. 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`. 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 https://gitlab.com/gitlab-org/gitlab/-/issues/233259
parent 0fd3111d
---
title: Fix time zone config not respected in multi-threaded servers
merge_request: 39778
author:
type: fixed
Time.zone = Gitlab.config.gitlab.time_zone || Time.zone Time.zone = Gitlab.config.gitlab.time_zone || Time.zone
# The default is normally set by Rails in the
# active_support.initialize_time_zone Railtie, but we need to set it
# here because the config settings aren't available until after that
# runs. We set the default to ensure multi-threaded servers have the
# right value.
Time.zone_default = Time.zone
Rails.application.config.time_zone = Time.zone
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment