Repository navigation
Description
Description
Three integration tests in client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java fail intermittently. Each one selects now() as t and toDateTime(now(), '<tz>') in the same query, and asserts that both columns hold the same instant. The server does not guarantee this. At a second boundary, column t can be one second earlier than the other columns. This is a test defect: the client decodes the values correctly.
Affected tests (they also run in the subclass QueryServerContentLZ4CompressionTests):
| Test | Query line | Failing assertion |
|---|---|---|
testServerTimeZoneFromHeader |
1997 | 2010 |
testClientUseOwnTimeZone |
2026 | 2041 |
testServerTimezone |
2335 | 2342 |
Line numbers are for the main commit in Environment.
Steps to reproduce
- Run this query on a ClickHouse server. The scalar subquery runs during analysis, between the two clock reads:
Result:
SELECT now() AS t, (SELECT sleep(2)) AS s, toDateTime(now(), 'UTC') AS utc_time
2026-11-17 16:16:56 0 2026-11-17 16:16:58. The values differ by 2 s. - Run the same query in these forms. The values are equal in each one:
SELECT now(), (SELECT sleep(2)) AS s, toDateTime(now(), 'UTC') AS utc_time(no alias onnow())WITH now() AS n SELECT n AS t, (SELECT sleep(2)) AS s, toDateTime(n, 'UTC') AS utc_time- the step 1 query with
SETTINGS enable_analyzer = 0
- Run the exact query of
testClientUseOwnTimeZonewith no sleep, in 6 concurrentclickhouse-client --queries-filestreams of 20000 queries each, withdate_time_output_format = 'unix_timestamp'. 1 of 120000 results had a mismatch:1794932293 1794932294 1794932294(columnt1 s earlier). The Java client was not used, so the client cannot be the cause.
Error Log or Exception StackTrace
CI, check Java client ( client-v2 ) + CH 26.3, on two unrelated PRs:
- Fix client-v2: size a bare Enum type name from its values #3345, 2026-11-17, https://github.com/ClickHouse/clickhouse-java/actions/runs/44118896944/job/134166771147
[ERROR] QueryTests.testClientUseOwnTimeZone:2041 expected [2026-11-17T15:56:05Z[UTC]] but found [2026-11-17T15:56:04Z[UTC]] - [client-v2, jdbc-v2] Disable Apache HttpClient wire logging for client connections #3252, 2026-10-22, https://github.com/ClickHouse/clickhouse-java/actions/runs/39836370718/job/120027005363
[ERROR] QueryServerContentLZ4CompressionTests>QueryTests.testClientUseOwnTimeZone:2041 expected [2026-10-22T19:08:47Z[UTC]] but found [2026-10-22T19:08:46Z[UTC]]
On the same head as #3345, the same test passed on the client-v2 legs for CH 25.8, 26.8 and latest. A failure needs a clock read on each side of a second boundary, so it is rare on every server version. Both failures are on the 26.3 leg, but other versions can fail too (see Root cause).
The failing assertion is always t vs utc_time, and t is always the earlier value. The comparison utc_time vs est_time in testServerTimezone cannot fail, because those two columns share one now() node.
Expected Behaviour
The tests pass on every run. They compare values that come from one clock read.
Root cause
- The analyzer builds each
now()call separately, and each build reads the clock:src/Functions/now.cpp:133(clock_gettime(CLOCK_REALTIME, ...)inNowOverloadResolver::buildImpl). - The analyzer shares one built function between calls with equal query-tree hashes (
functions_cache,src/Analyzer/Resolve/resolveFunction.cpp:1236-1252and:1498-1504, tagv26.3.9.8-lts). The hash includes the alias (compare_aliases = trueby default,src/Analyzer/IQueryTreeNode.h:139). Sonow() as tand the un-aliasednow()insidetoDateTime(now(), 'UTC')read the clock two times.
master (now.cpp, resolveFunction.cpp) has the same logic. The fix is in the three test queries only.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Code Example
// testClientUseOwnTimeZone, QueryTests.java:2026
client.query("SELECT now() as t, toDateTime(now(), 'UTC') as utc_time, " +
"toDateTime(now(), 'Europe/Lisbon')" +
"SETTINGS session_timezone = '" + requestTimeZone + "'")Configuration
Environment
- Cloud
- Client version:
mainat 93e50fa (0.12.0-rc1-SNAPSHOT) - Language version: CI matrix (the failures were on the client-v2 legs)
- OS: GitHub Actions
ubuntu-latest; local reproduction in a Linux container
ClickHouse Server
- ClickHouse Server version: 26.3 (CI); 26.3.66.4 (local reproduction)
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none
Found by our PR monitor across unrelated CI runs of our own PRs. Shortened on 2026-11-20: the edit history has the first version.
Activity