Skip to content

Flaky test: client-v2 cluster legs — insert right after CREATE TABLE hangs 1800 s with UNKNOWN_STATUS_OF_INSERT (quorum never reached) #3246

Open

Description

@polyglotAI-bot

Description

In the client-v2 + CH cluster <version> CI jobs, one test method sometimes hangs for 1800 s and then fails with Code: 319 UNKNOWN_STATUS_OF_INSERT ... Timeout while waiting for quorum. The failing method changes from run to run (mostly RowBinaryFormatWriterTest, once InsertTests). The job then runs about 39 minutes of its 40-minute limit, or is cancelled. In each run, the other cluster legs of the same commit passed.

The hang occurs when a test inserts into a table a few milliseconds after CREATE TABLE. A test retry or @Ignore does not help: the stall occurs before the test can retry anything.

Steps to reproduce

Local, without Testcontainers: a plain Docker Compose stack with the repo's own container files (clickhouse-keeper/keeper_config.xml, plus three replicas built from clickhouse-server/ with clickhouse-cluster/config.d/custom_config.xml and clickhouse-cluster/users.d/cluster_quorum.xml). Each container has a 0.5 CPU limit, to imitate a loaded runner.

  1. Create the database on each replica, as ClickHouseContainerStarter.createDatabase does:
    CREATE DATABASE tdb ENGINE = Replicated('/clickhouse/databases/tdb', 's1', 'rN')
  2. Repeat in one session on clickhouse-1, with no gap between CREATE and INSERT (as in the Java tests), with async_insert=0 and a new insert_deduplication_token for each table:
    DROP TABLE IF EXISTS t_i; CREATE TABLE t_i (id UInt32, s String) ORDER BY id; INSERT INTO t_i VALUES (i, 'x');
  3. If the INSERT fails, retry it with the same token, as client-v2 does.

Result:

  • Synchronous inserts: 2 of ~115 iterations hung (the first attempt still waited at 300 s, and the retry also hung). About 1 in 10 iterations got 285 TOO_FEW_LIVE_REPLICAS first, and the retry then passed.
  • With the server default async_insert=1 (default on 26.3+): 3 of ~340 iterations hung the same way.
  • With CREATE and INSERT in separate client processes (a gap of 100 ms or more): 0 of 200 hung.

Every hung table had this state:

-- system.parts: all_0_0_0 is active on clickhouse-1, -2 and -3
-- system.replicas (all 3): active_replicas = 3, total_replicas = 3, queue_size = 0
-- Keeper /clickhouse/tables/<uuid>/s1/quorum/parallel/all_0_0_0:
version: 1
part_name: all_0_0_0
required_number_of_replicas: 3
actual_number_of_replicas: 2
replicas:
r1
r3

Server log for one hung table (j_13, UTC):

r1 20:42:04.839  CREATE TABLE j_13 ... QueryFinish (2381 ms)
r2 20:42:04.733  Creating replica /clickhouse/tables/af491442-.../s1/replicas/r2   <- r2 still runs the CREATE from the database DDL log
r1 20:42:04.850  Wrote block with 1 rows (quorum 3 of 3 replicas)
r2 20:42:04.851  Will mimic r1
r3 20:42:04.904  Quorum .../quorum/parallel/all_0_0_0 still not satisfied (have only 2 of 3 replicas), updating node
r2 20:42:04.948  Enqueued fetches after mimic: all_0_0_0                          <- copied entry, no quorum info
r2 20:42:04.970  Insert entry queue-0000000001 to queue with type GET_PART ... [all_0_0_0]   <- log entry with "quorum: 3"
r2 20:42:05.049  Not executing log entry queue-0000000001 of type GET_PART for part all_0_0_0 because another log entry queue-0000000000 of type GET_PART for the same part ...
r2 20:42:05.049  DDLWorker(tdb): Executed query: ... CREATE TABLE tdb.j_13 ...
r2 20:42:05.245  Part all_0_0_0 committed to zookeeper                            <- fetched through the copied entry; quorum node not updated
r1 20:42:04.869 → Waiting for quorum '.../quorum/parallel/all_0_0_0' ... still exists, will wait for updates  (until the 600 s timeout)

Error Log or Exception StackTrace

From run 39659780341 (failsafe TestSuite-output.txt):

19:25:01 WARN Client - Insert (stream) failed (attempt 1 of 4, queryId: 08ad3e40-...), ... Code: 999. DB::Exception: <Unreadable error message> (transport error: 500)
19:35:01 WARN Client - Insert (stream) failed (attempt 2 of 4, queryId: 08ad3e40-...), ... Code: 319. DB::Exception: Unknown quorum status. The data was inserted in the local replica but we could not verify quorum. Reason: Timeout while waiting for quorum. (UNKNOWN_STATUS_OF_INSERT)
19:45:01 WARN Client - Insert (stream) failed (attempt 3 of 4, queryId: 08ad3e40-...), ... Code: 319. ... Timeout while waiting for quorum.
19:55:01 WARN Client - Insert request failed (attempt: 4, duration: 1800143ms, queryId: 08ad3e40-...)

[ERROR] RowBinaryFormatWriterTest.writeAndReadImageTest:700 » Server Code: 319. DB::Exception: Unknown quorum status. ... (version 26.9.19.9 (official build))

Before this, the same run logged Code: 285 ... Number of alive replicas (2) is less than requested quorum (3/3) four times (retried and passed), and Code: 999 ... Transaction failed (No node): Op #0, path: /clickhouse/tables/<uuid>/s1/replicas/r2/is_active. Both errors show inserts that arrive while a replica still starts the new table. In run 38997313350, attempt 1 failed with 285, and attempts 2–4 each waited 600 s.

The runs are on unrelated PRs and on main:

Run / job Date Branch Server Test Result
37846989852 2026-10-08 dependabot (examples) 26.3.45.3 InsertTests.testPOJOWithDynamicType:825 319 after 1800 s
37856327275 2026-10-08 main 26.9.13.15 RowBinaryFormatWriterTest.writeNestedWithArrayAndComplexFieldsTests 319 after 1800 s
38791897060 2026-10-15 PR branch 25.8 — job cancelled at the 40-min limit, no report (probably the same; not confirmed)
38859419535 2026-10-16 PR #3215 26.9.19.9 RowBinaryFormatWriterTest.writeNumbersTest 319 after 1800 s
38997313350 2026-10-17 main 26.9.19.9 RowBinaryFormatWriterTest.writeMissingFieldsTest 319 after 1800 s
39659780341 2026-10-21 PR #3245 26.9.19.9 RowBinaryFormatWriterTest.writeAndReadImageTest:700 319 after 1800 s

Frequency: 5 confirmed (+1 probable) of 156 client-v2 + CH cluster jobs (52 workflow runs × 3 versions) since the cluster jobs were added on 2026-10-05, about 1 workflow run in 10. It is not specific to latest: 26.3 and 26.9 are confirmed.

Expected Behaviour

An insert into a new table in the cluster test environment completes when all replicas have the part. The cluster legs do not fail or hang because of when a test inserts relative to CREATE TABLE.

Root cause.

  • Server side: a replica that joins the new table by a copy of the part list of another replica ("mimic", log above) gets the part but does not add itself to the quorum node, so the node stays at 2 of 3 until insert_quorum_timeout. This looks like a ClickHouse server bug (probably also for users who add a replica during quorum inserts), for a separate ClickHouse/ClickHouse report; this issue is only about the test harness.
  • clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml:5-6: each insert needs all 3 replicas (insert_quorum=3) and waits up to 600 s.
  • clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java:87: the test database is Replicated, so CREATE TABLE can return while another replica still applies it from the database DDL log.
  • client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java:102-114 (initTable) and :195-198 (writeTest) insert right after CREATE and getTableSchema, with no wait. InsertTests uses the same pattern.
  • client-v2/src/main/java/com/clickhouse/client/api/ServerException.java:73 and ClientConfigProperties.java:139,157-159 make 319 retryable by default, with 4 attempts (Client.java:1861,1872); each retry has the same deduplication token and waits on the same stuck quorum node (3 × 600 s = 1800 s). The retry is a normal recovery and is not the bug.
  • .github/workflows/build.yml:342: timeout-minutes: 40 for test-with-cluster.

The fix is in the test code and the CI configuration only.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.

Related: #3237 / #3239: same cluster harness, a different replication-lag race (users and roles).

Code Example

Not needed: the steps above use SQL only. The client configuration of the tests is below.

Configuration

Client Configuration

// RowBinaryFormatWriterTest.newClient() — the relevant parts
new Client.Builder()
    .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), false) // nginx in front of 3 replicas
    .serverSetting(ServerSettings.ASYNC_INSERT, "0")
    .serverSetting(ServerSettings.WAIT_END_OF_QUERY, "1");
// InsertSettings: setDeduplicationToken(random 36 chars), setQueryId(random UUID)
// retry defaults: retry=3, client_retry_on_failures includes ServerRetryable

Environment

  • Cloud
  • Client version: main @ 7f2cb5787
  • Language version: Java 17 (CI test-with-cluster job)
  • OS: GitHub-hosted ubuntu-latest (CI); Ubuntu 24.04 + Docker 29 (local reproduction)

ClickHouse Server

  • ClickHouse Server version: 26.9.19.9, 26.9.13.15, 26.3.45.3 in CI; 26.9.19.9 locally
  • ClickHouse Server non-default settings, if any: the cluster profile (cluster_quorum.xml, above), default_table_engine=ReplicatedMergeTree; Replicated database; 3 replicas + 1 Keeper (session_timeout_ms=30000) behind nginx
  • CREATE TABLE statements for tables involved: any new table; the local reproduction used the table in step 2
  • Sample data for all these tables: one row

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

  1. polyglotAI-bot commented on Nov 24, 2026

    @polyglotAI-bot
    CollaboratorAuthor

    Since 2026-11-17, the same stall fails the cluster legs with a different error. On servers where async_insert=1 is the default (26.3+), the INSERT waits in WaitForAsyncInsert. After wait_for_async_insert_timeout (120 s), the server returns:

    Code: 159. DB::Exception: Wait for async insert timeout (120000 ms) exceeded: While executing WaitForAsyncInsert. (TIMEOUT_EXCEEDED)
    

    client-v2 does not retry 159 (ServerException.java:63-79), so the job does not hang: one test fails after 120.1–120.4 s. The affected tests insert with the server default settings right after CREATE TABLE, for example PojoReaderDataSetTest.java:128-130 (once for each data set), SpanRecorderTest.java:44-46 and RowBinaryTest.java (testGetObjectArray*).

    Run / job Date Branch Server Test
    43979145572 2026-11-17 branch push 26.8.38.9 JacksonJSONEachRowFormatReaderTests.setUpPrimitivesTable
    44140507366 2026-11-17 main 26.10.4.207 RowBinaryTest.testGetObjectArray1D
    44148232271 2026-11-17 branch push 26.8.39.19 RowBinaryTest.testGetObjectArray3D
    44192568455 2026-11-17 branch push 26.10.4.207 RowBinaryTest.testGetObjectArray2D
    44198894996 2026-11-17 branch push 26.10.4.207 PojoReaderDataSetTest.testReadDataSetWithPojo
    44470483306 2026-11-19 PR #3392 26.10.4.207 SpanRecorderTest.setUp
    45282254061 2026-11-23 main 26.8.45.6 BaseReaderTests.testReadingInstantFromVariant, testReadingLocalTimeFromDynamic
    45288698626 2026-11-23 PR #3403 26.8.45.6 RowBinaryTest.testGetObjectArrayMultipleRows
    45295477037 2026-11-24 PR #3404 26.10.4.207 PojoReaderDataSetTest.testReadDataSetWithPojo
    45297478697 2026-11-24 PR #3407 26.10.4.207 PojoReaderDataSetTest.testReadDataSetWithPrimitivePojo

    Frequency: 10 of the 72 Build runs since 2026-11-10 (10 of the 144 26.8 and latest cluster jobs; none on 25.8 or 26.3). In the same period, one job failed with 319.

    Local reproduction, with the Docker Compose stack of the issue, CH 26.10.4.207, 1 CPU and 2 GiB for each replica, and requests through the repo's nginx config: 8 parallel loops of DROP TABLE IF EXISTS t / CREATE TABLE t (id Int32, name String) ORDER BY id / INSERT INTO t VALUES (1, 'a'), (2, 'b'), (3, 'c') (as SpanRecorderTest.setUp), with the server default settings.

    • 4 of 1200 inserts failed with 159 (HTTP 408) after 120.01 s.
    • These 4 tables are the only tables where a replica logged Enqueued fetches after mimic: all_0_0_0. The log chain is the same as above: Will mimic r1, then Not executing log entry queue-0000000001 of type GET_PART for part all_0_0_0 ....
    • The server-side flush continued to wait on quorum/parallel/all_0_0_0 after the client got 159. It failed with Code: 319 ... Timeout while waiting for quorum 600 s after it started.
    • Contrast: with SYSTEM SYNC DATABASE REPLICA on each replica between CREATE TABLE and INSERT, 0 of 1200 inserts failed.

    Found by our PR monitor across unrelated CI runs of our own PRs. Verified against a live server.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions