Skip to content

Avoid eager local timezone lookup when ClickHouse sends a timezone header - #576

Open
sadokfire wants to merge 1 commit into
ClickHouse:masterfrom
sadokfire:fix/lazy-clickhouse-timezone-fallback
Open

Avoid eager local timezone lookup when ClickHouse sends a timezone header#576
sadokfire wants to merge 1 commit into
ClickHouse:masterfrom
sadokfire:fix/lazy-clickhouse-timezone-fallback

Conversation

@sadokfire

@sadokfire sadokfire commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Avoid evaluating Poco::Timezone::name() when the ClickHouse response already
contains X-ClickHouse-Timezone.

Root cause

The existing call used Poco::Timezone::name() as the default argument to
response->get(). C++ evaluates that argument before calling get(), even
when the response header is present. On glibc, Poco::Timezone::name() calls
tzset() and reads tzname. Concurrent localtime_r() activity can leave
tzname[0] null between those operations, causing a crash even though the
driver then uses the server-provided timezone.

Changes

  • Resolve the response timezone through a lazy fallback function, so
    Poco::Timezone::name() is called only if the header is absent.
  • Add deterministic tests for present nonempty, present empty, and absent
    timezone headers. The present-header tests supply a fallback that fails if it
    is evaluated.

The change preserves the existing absent-header fallback and an explicitly
present empty header.

Validation

  • Oracle Linux 9.8 (glibc 2.34): all 548 ANSI and 548 Unicode unit tests pass.
  • The three Statement.ResponseTimezone* tests pass in both ANSI and Unicode
    executables.
  • Fresh real UnixODBC harness run against ClickHouse 26.6.1.1193:
    • 5-second control: 4,772 queries, 0 conversions, result=0;
    • 10-second concurrent localtime_r() run: 11,794 queries,
      263,262,925 conversions, result=0.
  • The unmodified driver was previously reproduced crashing with exit 139 under
    the same concurrent workload; the Docker bundle contains the complete flow.

Manual reproduction

Attach clickhouse-odbc-timezone-race-reproducer-v2.zip from this change. It
contains the Docker build environment, UnixODBC harness, expected baseline
failure, fixed-driver verification, and cleanup commands.

@sadokfire
sadokfire requested review from mzitnik and slabko as code owners July 29, 2026 13:59
@CLAassistant

CLAassistant commented Jul 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sadokfire

Copy link
Copy Markdown
Author

@sadokfire
sadokfire force-pushed the fix/lazy-clickhouse-timezone-fallback branch from 8add63c to d7b6215 Compare July 29, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants