Skip to content

Fix flaky test test_nats_jet_stream_skipped_broken_message_is_not_redelivered_after_reconnect - #124849

Merged
fm4v merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/nats-skipped-message-reconnect-window
Nov 19, 2026
Merged

fm4v merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/nats-skipped-message-reconnect-window

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 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):

Fix flaky test test_nats_jet_stream_skipped_broken_message_is_not_redelivered_after_reconnect.

Description

Related: #119301 (re-landed this test).

The [hard_kill] arm failed with no streaming source performed an in-source recovery in Integration tests (amd_msan, targeted) (report). It is the test's only failure in 30 days, and no issue exists for it.

The broker restart has to land inside the streaming cycle that holds the skipped message, because only that cycle can do the in-source recovery, and the test cannot retry. That cycle lasted nats_flush_interval_ms = 30000. In the failed job, docker kill of the broker took 32.4 s instead of about 0.2 s (dockerd: Container failed to exit within 10s of kill - trying direct SIGKILL). The cycle ended first (Reschedule streaming. Unable to restore connection), the client reconnected between cycles, and the background task recovered the subscription instead.

The table now uses nats_flush_interval_ms = 300000, which is still below the consumer's 600 s ACK wait, and nats_max_block_size = 1. A skipped message yields no rows, so it cannot end the cycle, while the good row published at the end ends it at once. The test therefore no longer waits out the flush interval. The assertions are unchanged.

Validation (native pytest, master debug binary):

  • With a 33 s stall added after docker kill (local patch, not committed), the test fails 3/3 before the change with the CI error and passes 3/3 after it.
  • 40/40 runs of both arms pass, and per-arm p50 drops from about 31.5 s to 6.6-7.5 s.
  • With the in-source recovery mutated to hand the skipped message back (NATSSource.cpp), the changed test fails 2/2, as the original test does.
  • The whole test_nats_jet_stream.py module passes (59 tests).

Workflow [PR]
Sync PR [sync-upstream/pr/124849]

Version info

  • Merged into: 26.11.1.2885-master (included in 26.11 and later)

…elivered_after_reconnect

The test needs the broker restart to land inside the streaming cycle that
holds the skipped message, since only that cycle can do the in-source
recovery and the test cannot retry. With `nats_flush_interval_ms = 30000`
that cycle lasted 30 s from its start. In the failed job `docker kill` of
the broker took 32.4 s (dockerd: "Container failed to exit within 10s of
kill - trying direct SIGKILL"), so the cycle ended before the reconnect,
the background task recovered the subscription between cycles, and the
wait for the in-source recovery line expired:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124700&sha=36167c0b2625e48cbd2369a3b19e22676b78c4ad&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%20targeted%29

Use a 300 s flush interval, still below the consumer's 600 s ACK wait, so
the cycle stays open across any restart the module tolerates, and
`nats_max_block_size = 1`: a skipped message yields no rows and cannot end
the cycle, while the good row published at the end ends it at once. The
test no longer waits out the flush interval (per-arm p50 31.4 s -> 6.6-7.5 s
locally). The assertions are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

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

Pre-publication review by an independent model (engine: codex): 0 findings. My own cold review of the same diff (engine side of nats_max_block_size and nats_flush_interval_ms in NATSSource::generateImpl, teardown with the cycle in flight, sibling recovery tests, oracle liveness under a hand-back mutation): 0 findings.

# Sev Finding Verdict Evidence / action
- - none - -

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20261009-071600

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A hard_kill arm with a 33 s stall after docker kill (models the 32.4 s stall in the CI job) fails 3/3 on master with no streaming source performed an in-source recovery.
b Root cause explained? Yes. The cycle holding the skipped message lasted 30 s. The slow kill moved the reconnect past it, so the background task recovered the subscription between cycles and the in-source wait expired.
c Fix matches root cause? Yes. The cycle window (300 s) no longer depends on how long a restart takes, and nats_max_block_size = 1 lets the final good row end the cycle. No assertion bound was widened and no tag was added.
d Test intent preserved / new tests added? Yes. The oracles are unchanged. Making the recovery hand the skipped message back still fails the changed test (ack floor stays at 0), as it failed the old one (2 deliveries).
e Both directions demonstrated? Yes. With the stall: 3/3 FAIL before, 3/3 PASS after. Without it: 40/40 PASS.
f Fix is general across code paths? Yes. The other in-source recovery tests use a 60 s cycle with up to 3 restarts, and the direct SELECT tests use a 120 s window. The whole module passes (59 tests).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only timing fix). Both restart arms are covered.
h Backward compatible? (maintainer-approved exception only) N/A (test-only).
i Invariants and contracts preserved? Yes. The 300 s cycle stays below the 600 s ACK wait, so a redelivery can still only come from a hand-back. Teardown with the cycle in flight finished promptly in every run.

Session id: cron:clickhouse-impl-slot-41:20261009-061700

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [497a204]

Summary: ✅


AI Review

Summary

Reviewed #124849 at 497a204726b3160e0df5086f9e8152e59f397d7a. The change keeps the NATS regression test's streaming cycle open across slow broker restarts using nats_flush_interval_ms = 300000, while nats_max_block_size = 1 lets the final valid row flush immediately. No actionable findings. The author reports a before/after reproduction with a 33-second stall, repeated successful runs of both restart variants, a mutation check that still detects incorrect message handling, and 59 passing module tests.

Missing context / blind spots
  • ⚠️ Integration tests were not rerun locally during this review. Targeted sanitizer and ARM integration jobs for the reviewed head were still running; their completed results will provide independent CI confirmation of the author's reported validation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 45b9413

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (amd_asan_ubsan), Build (amd_msan), Build (amd_tsan) / Build ClickHouse master-side build break, not from this PR (which only changes tests/integration/test_storage_nats/test_nats_jet_stream.py): src/Common/Scheduler/Nodes/tests/gtest_throttler_constraint.cpp:25:11: error: use of undeclared identifier 'FifoQueue', the only error in each of the three builds. All three builds fail on every one of the 27 true-master commits since 2026-10-09 00:35Z #124798 (external, open)
Mergeable Check, PR praktika rollups of the row above (Failed: Build (amd_asan_ubsan),Build (amd_tsan),Build (amd_msan), Dropped: 5), no independent failure #124798 (external, open)
CH Inc sync - CH Inc sync (private, not actionable by me)

All 163 check runs completed and Finish Workflow is green. 5 jobs were dropped behind the three sanitizer builds, so the changed NATS test has not run on this head yet.

Session id: cron:our-pr-ci-monitor:20261009-083002

@fm4v
fm4v added this pull request to the merge queue Nov 19, 2026
Merged via the queue into ClickHouse:master with commit 39e3866 Nov 19, 2026
194 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). and removed comp-testing Test content only (no production code). labels Nov 19, 2026
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 comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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.

3 participants