hermes - 💡(How to fix) Fix concurrency: get_timezone() TOCTOU — _cache_resolved set after _cached_tz written [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fixed

Code Example

def get_timezone() -> Optional[ZoneInfo]:
    global _cached_tz, _cached_tz_name, _cache_resolved
    if not _cache_resolved:
        _cached_tz_name = _resolve_timezone_name()
        _cached_tz = _get_zoneinfo(_cached_tz_name)
        _cache_resolved = True   # flag set LAST
    return _cached_tz
RAW_BUFFERClick to expand / collapse

Bug

hermes_time.get_timezone() uses a lazy-init singleton with a classic TOCTOU race:

def get_timezone() -> Optional[ZoneInfo]:
    global _cached_tz, _cached_tz_name, _cache_resolved
    if not _cache_resolved:
        _cached_tz_name = _resolve_timezone_name()
        _cached_tz = _get_zoneinfo(_cached_tz_name)
        _cache_resolved = True   # flag set LAST
    return _cached_tz

Two concurrent threads both see not _cache_resolved, both call _resolve_timezone_name() (file I/O + env-var read), and both race on the global assignments. On non-GIL runtimes (CPython 3.13+ free-threaded, PyPy) the assignment to _cache_resolved = True and _cached_tz = … can be re-ordered, so a third thread may see _cache_resolved=True but read the stale None default from _cached_tz.

get_timezone() is called by now(), which is in the hot path of every tool execution. Under concurrent gateway load this races on every cold start.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix concurrency: get_timezone() TOCTOU — _cache_resolved set after _cached_tz written [1 pull requests]