Skip to content

Fix flaky test_s3_table_functions_timeouts - #111506

Merged
CheSema merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/s3-table-functions-timeouts-flaky
Jul 23, 2026
Merged

CheSema merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/s3-table-functions-timeouts-flaky

Conversation

@groeneai

@groeneai groeneai commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

test_s3_table_functions/test.py::test_s3_table_functions_timeouts injects a 1200ms network delay and expects an S3 INSERT to time out and raise. It set no explicit S3 timeout, so the raise relied on a default timeout being below 1200ms on the connection path actually taken:

  • Fresh connection: the adaptive connect timeout (500ms first attempt, 1000ms on retries) is below 1200ms, so the connect times out and the query raises. This is the normal path.
  • Reused pooled keep-alive connection: no fresh TCP connect happens, so the connect timeout does not apply. The only remaining gate is the send/receive idleness timeout, whose default (adaptive 3000ms / configured 30000ms) is far above 1200ms, so the write completes and pytest.raises sees no exception. This is the rare DID NOT RAISE failure reported on the report for Fix signed integer overflow in toStartOfSubsecondInterval when rounding near INT64_MIN #111370 (one occurrence in 40 days of CI, 0 on master).

Fix: set s3_request_timeout_ms=500 for the timeout query. This idleness timeout applies to every attempt on both fresh and reused connections, so the 1200ms delay always exceeds it and the write times out deterministically. Test intent is preserved (a slow network still makes the write fail), and the change is confined to the timeout query settings.

Validated: reproduced DID NOT RAISE deterministically by modeling the reused-connection path (no sub-1200ms timeout governing), confirmed the fix raises with s3_request_timeout_ms=500, and ran the modified test 5 times (--count 5 --random-order), all passing.

Version info

  • Merged into: 26.8.1.39 (included in 26.8 and later)

The test injects a 1200ms network delay and expects an S3 INSERT to time out
and raise. It set no explicit S3 timeout, so raising relied on a default
timeout being below 1200ms on the connection path actually taken. On a fresh
connection the adaptive connect timeout (500ms first attempt, 1000ms on
retries) trips reliably. But when the S3 request reuses a pooled keep-alive
connection there is no fresh TCP connect, so the connect timeout does not
apply; the only remaining gate is the send/receive idleness timeout, whose
default (adaptive 3000ms / configured 30000ms) is far above 1200ms, so the
write completes and pytest.raises sees no exception. That is the rare
DID NOT RAISE flake (one occurrence in 40 days of CI, zero on master).

Make the request timeout the single failure mechanism: disable adaptive
timeouts, keep the connect timeout above the delay, and set
s3_request_timeout_ms=500. The send/receive idleness timeout applies to every
attempt on both fresh and reused connections, so the 1200ms delay always
exceeds it and the write times out deterministically. Also assert the raised
error is a timeout, so the test cannot pass on an unrelated error.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Modeling the reused-connection path (no timeout below 1200ms governing) reproduces DID NOT RAISE on demand; and reverting the fix in the shipped settings makes the test not raise (verified).
b Root cause explained? Yes. The raise relied on an implicit default timeout below 1200ms. On a reused pooled connection the connect timeout is skipped and the only remaining gate (send/receive idleness) defaults to 3000ms/30000ms, far above 1200ms, so the write completes and nothing is raised.
c Fix matches root cause? Yes. Sets the send/receive idleness timeout (s3_request_timeout_ms=500), exactly the gate missing on the reused-connection path, and pins the connection timeout out of the way so the request timeout is the sole mechanism.
d Test intent preserved? Yes, and strengthened. Still asserts a slow network makes the S3 write fail; now also asserts the error is a timeout (match="Timeout") so it cannot pass on an unrelated error. No no-random/no-parallel tag; other test untouched.
e Demonstrated both directions? Yes. Reverting the fix under the shipped settings gives no raise; with the fix it raises a Code: 499 ... Timeout S3 error. Real test run 5x under --random-order, all pass.
f General, not a narrow patch? Yes (test scope). The request/idleness timeout covers both fresh and reused connections and every retry attempt, unlike clearing the connection cache which only forces the fresh-connect path.
g Generalizes across inputs? N/A (no engine change). The relevant axis is connection reuse state; the fix is robust across fresh and reused connections.
h Backward compatible? Yes. Test-only; no engine, setting-default, or format change.
i Invariants/contracts preserved? Yes. No engine code touched; no server-global state mutated (connection-cache clearing deliberately avoided to keep the test parallel-safe).

Session id: cron:clickhouse-author-slot-0:20260723-001054

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

An independent model reviewed the diff before submission. One finding, adjudicated:

⚠️ Majors

  • Test liveness (AGREE, fixed). The first version was not "live": with adaptive timeouts on, a fresh connection already trips the 500ms adaptive connect timeout, so the test would have passed even with the fix reverted (it only regressed on the rare reused-connection path), and it accepted any QueryRuntimeException. Fixed by disabling adaptive timeouts and raising the connect timeout above the delay so the request timeout is the sole failure mechanism, and asserting match="Timeout". Re-verified: reverting the fix under these settings yields no raise; with the fix it raises a Code: 499 ... Timeout S3 error. Re-review after the fix: no findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 - could you review? Test-only fix for flaky test_s3_table_functions_timeouts: it relied on a default S3 timeout below the injected 1200ms delay, which the connect timeout only satisfies on a fresh connection; on a reused pooled connection nothing under 1200ms applied, so the write occasionally did not time out. Sets s3_request_timeout_ms=500 as the sole failure mechanism and asserts the error is a timeout.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bf0f909]

Summary: ✅


AI Review

Summary

This PR makes test_s3_table_functions_timeouts deterministic by switching the test from relying on whichever implicit S3 timeout happens to fire first to an explicit s3_request_timeout_ms, while also pushing s3_connect_timeout_ms above the injected 1200 ms delay so the connect timeout no longer masks the intended path. I reviewed the current diff, the surrounding integration test setup, the network-delay helper, and the S3 timeout plumbing in the object-storage client path, and I did not find a remaining correctness or coverage issue in the current version.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 23, 2026
@CheSema CheSema self-assigned this Jul 23, 2026
@CheSema
CheSema added this pull request to the merge queue Jul 23, 2026
Merged via the queue into ClickHouse:master with commit 41328f4 Jul 23, 2026
178 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jul 30, 2026
…eouts-flaky-26.7

Backport #111506 to 26.7: Fix flaky test_s3_table_functions_timeouts
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ions-timeouts-flaky

Fix flaky test_s3_table_functions_timeouts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants