Skip to content

cobalt: Set the ICU default timezone before using it - #13069

Merged
jellefoks merged 1 commit into
youtube:mainfrom
hferreiro:nplb-tz
Oct 2, 2026
Merged

jellefoks merged 1 commit into
youtube:mainfrom
hferreiro:nplb-tz

Conversation

@hferreiro

Copy link
Copy Markdown
Collaborator

PosixTimezoneTests.HandlesUnsetTZEnvironmentVariable and
PosixTimezoneTests.TimezoneIsNotSet hung on AOSP.

Without TZ, constructing IcuTimeSupport creates ICU calendars before an
ICU default timezone is set, so ICU detects it from /etc/localtime.
Android has none, so ICU calls localtime_r(), which waits for the
IcuTimeSupport instance being constructed, and the thread deadlocks.

Set the ICU default from SbTimeZoneGetName() before the timezone is
created. EnsureTimeZoneIsCreated() still replaces it with the one from
TZ.

Bug: 552779286

PosixTimezoneTests.HandlesUnsetTZEnvironmentVariable and
PosixTimezoneTests.TimezoneIsNotSet hung on AOSP.

Without TZ, constructing IcuTimeSupport creates ICU calendars before an
ICU default timezone is set, so ICU detects it from /etc/localtime.
Android has none, so ICU calls localtime_r(), which waits for the
IcuTimeSupport instance being constructed, and the thread deadlocks.

Set the ICU default from SbTimeZoneGetName() before the timezone is
created. EnsureTimeZoneIsCreated() still replaces it with the one from
TZ.

Bug: 552779286
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Context State Description
CI / All Pass ✅ PASS All checks passed
CI / android ✅ PASS Passed
CI / evergreen ✅ PASS Passed
CI / linux ✅ PASS Passed
CI / tvos ✅ PASS Passed
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


cobalt: Set ICU default timezone before use

Initialize the ICU default timezone during the construction of
TimeZoneState to prevent circular dependencies.

On platforms like Android (AOSP) that lack an /etc/localtime file, ICU
attempts to determine the system timezone by calling localtime_r().
This causes a deadlock because localtime_r() waits for the
TimeZoneState singleton to be fully constructed. By setting an
initial default from the platform, ICU avoids the automatic detection
logic that triggers the hang. This default is replaced later by the
timezone specified in the TZ environment variable.

This change allows enabling PosixTimezoneTests on AOSP-based Evergreen
builds.

Bug: 552779286

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request sets a temporary default ICU timezone in the TimeZoneState constructor using SbTimeZoneGetName() before calling EnsureTimeZoneIsCreated(). This prevents a deadlock on Android platforms where /etc/localtime is missing and ICU calls localtime_r(), which would otherwise wait indefinitely for the TimeZoneState object to be constructed. Additionally, timezone-related tests (PosixTimezoneTests.HandlesUnsetTZEnvironmentVariable and PosixTimezoneTests.TimezoneIsNotSet) have been re-enabled in the test filters for Evergreen Android platforms. I have no feedback to provide as there are no review comments and the implementation is correct.

@jellefoks
jellefoks merged commit a00c2ac into youtube:main Oct 2, 2026
535 of 539 checks passed
@github-actions github-actions Bot added the cp-27.lts Cherry Pick to the 27.lts branch label Oct 2, 2026
@hferreiro
hferreiro deleted the nplb-tz branch October 2, 2026 21:32
hferreiro added a commit to hferreiro/cobalt that referenced this pull request Oct 5, 2026
Follow-up to youtube#13069, where I
discovered this unused code.

FindLastDateWithDst() walked from 1970 to five years ahead, a week at a
time, looking for the last date with DST, to get the daylight name of
zones that abandoned DST. It was never called for those zones: it only
runs when useDaylightTime() is true, which ICU only returns for zones
that observe DST this year, so zones that abandoned it reuse the
standard name instead.

Remove it, together with the date parameter of ExtractZoneName(), which
only it passed.

Bug: 552779286
@oxve oxve removed the cp-27.lts Cherry Pick to the 27.lts branch label Oct 5, 2026
briantting pushed a commit that referenced this pull request Oct 6, 2026
…ing it

Refer to original PR: #13069

PosixTimezoneTests.HandlesUnsetTZEnvironmentVariable and
PosixTimezoneTests.TimezoneIsNotSet hung on AOSP.

Without TZ, constructing IcuTimeSupport creates ICU calendars before an
ICU default timezone is set, so ICU detects it from /etc/localtime.
Android has none, so ICU calls localtime_r(), which waits for the
IcuTimeSupport instance being constructed, and the thread deadlocks.

Set the ICU default from SbTimeZoneGetName() before the timezone is
created. EnsureTimeZoneIsCreated() still replaces it with the one from
TZ.

Bug: 552779286

(cherry picked from commit a00c2ac)
briantting pushed a commit that referenced this pull request Oct 16, 2026
…ing it

Refer to original PR: #13069

PosixTimezoneTests.HandlesUnsetTZEnvironmentVariable and
PosixTimezoneTests.TimezoneIsNotSet hung on AOSP.

Without TZ, constructing IcuTimeSupport creates ICU calendars before an
ICU default timezone is set, so ICU detects it from /etc/localtime.
Android has none, so ICU calls localtime_r(), which waits for the
IcuTimeSupport instance being constructed, and the thread deadlocks.

Set the ICU default from SbTimeZoneGetName() before the timezone is
created. EnsureTimeZoneIsCreated() still replaces it with the one from
TZ.

Bug: 552779286

(cherry picked from commit a00c2ac)
briantting pushed a commit that referenced this pull request Oct 16, 2026
…ing it

Refer to original PR: #13069

PosixTimezoneTests.HandlesUnsetTZEnvironmentVariable and
PosixTimezoneTests.TimezoneIsNotSet hung on AOSP.

Without TZ, constructing IcuTimeSupport creates ICU calendars before an
ICU default timezone is set, so ICU detects it from /etc/localtime.
Android has none, so ICU calls localtime_r(), which waits for the
IcuTimeSupport instance being constructed, and the thread deadlocks.

Set the ICU default from SbTimeZoneGetName() before the timezone is
created. EnsureTimeZoneIsCreated() still replaces it with the one from
TZ.

Bug: 552779286

(cherry picked from commit a00c2ac)
jellefoks pushed a commit that referenced this pull request Oct 23, 2026
Follow-up to #13069, where I
discovered this unused code.

FindLastDateWithDst() walked from 1970 to five years ahead, a week at a
time, looking for the last date with DST, to get the daylight name of
zones that abandoned DST. It was never called for those zones: it only
runs when useDaylightTime() is true, which ICU only returns for zones
that observe DST this year, so zones that abandoned it reuse the
standard name instead.

Remove it, together with the date parameter of ExtractZoneName(), which
only it passed.

Bug: 552779286
cobalt-github-releaser-bot pushed a commit that referenced this pull request Oct 23, 2026
Refer to original PR: #13104

Follow-up to #13069, where I
discovered this unused code.

FindLastDateWithDst() walked from 1970 to five years ahead, a week at a
time, looking for the last date with DST, to get the daylight name of
zones that abandoned DST. It was never called for those zones: it only
runs when useDaylightTime() is true, which ICU only returns for zones
that observe DST this year, so zones that abandoned it reuse the
standard name instead.

Remove it, together with the date parameter of ExtractZoneName(), which
only it passed.

Bug: 552779286

(cherry picked from commit fa1350b)
briantting pushed a commit that referenced this pull request Oct 27, 2026
Refer to original PR: #13104

Follow-up to #13069, where I
discovered this unused code.

FindLastDateWithDst() walked from 1970 to five years ahead, a week at a
time, looking for the last date with DST, to get the daylight name of
zones that abandoned DST. It was never called for those zones: it only
runs when useDaylightTime() is true, which ICU only returns for zones
that observe DST this year, so zones that abandoned it reuse the
standard name instead.

Remove it, together with the date parameter of ExtractZoneName(), which
only it passed.

Bug: 552779286

(cherry picked from commit fa1350b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants