Flaky test: R2DBCTestKitImplTest.batch intermittently fails with "Connection pool shut down"
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/ClickHouseBatch.java と ClickHouseConnection.java から始め、次に TestKit.batch と R2DBCTestKitImplTest#batch を調べます。提供されている Maven R2DBC HTTP 検証コマンドを実行し、接続が閉じる前にすべてのバッチリクエストが完了するかを追跡します。完了の条件は、接続プールのシャットダウンエラーなしにテストが決定的に完了することです。
索引モデルが issue の本文から書いたものです。
説明
Description
com.clickhouse.r2dbc.spi.test.R2DBCTestKitImplTest.batch (module clickhouse-r2dbc) fails intermittently in CI. The other 31 tests of the same class pass in the same run, and the sibling matrix legs (other r2dbc-spi versions / server versions) stay green, so an unrelated PR looks like it introduced a regression.
The failure is not a query failure: the Apache HttpClient connection manager is already shut down before the request leases a connection, and the test fails in ~0.04 s.
Steps to reproduce
- Run the R2DBC CI job:
mvn --batch-mode --projects clickhouse-r2dbc -DclickhouseVersion=<ver> -D'r2dbc-spi.version=<ver>' -Dprotocol=http verify. - Repeat. The failure is intermittent — a re-run of the identical commit passes.
Error Log or Exception StackTrace
java.lang.AssertionError: expectation "expectComplete" failed
(expected: onComplete(); actual: onError(java.lang.IllegalStateException: Connection pool shut down))
Suppressed: java.lang.IllegalStateException: Connection pool shut down
at org.apache.hc.core5.pool.LaxConnPool.lease(LaxConnPool.java:163)
at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.lease(...)
...
at com.clickhouse.client.http.ApacheHttpConnectionImpl.post(ApacheHttpConnectionImpl.java:301)
at com.clickhouse.client.http.ClickHouseHttpClient.send(ClickHouseHttpClient.java:196)
Evidence of non-determinism
Same commit, same check, fail then pass — run 32022532612 on PR #3056:
- attempt 1, leg
R2DBC 1.0.0.RELEASE + CH 26.3 (http)→ failure,Tests run: 32, Failures: 1,batch0.041 s: https://github.com/ClickHouse/clickhouse-java/actions/runs/32022532612/job/95368314131 - attempt 2, same leg, same head
7c4b7a66→ success (all six R2DBC legs green).
An independent second observation, two weeks earlier and on a different PR and matrix leg — PR #3010, head d341a338, which touches only jdbc-v2 (SqlParserFacade + its tests) and cannot reach the R2DBC/HTTP path:
- leg
R2DBC 0.9.1.RELEASE + CH latest (http)→ failure, identical signature,batch0.035 s: https://github.com/ClickHouse/clickhouse-java/actions/runs/30856790714/job/91832373067 - the other five R2DBC legs of that same run → success.
Local reproduction
Does not reproduce on an idle or loaded devbox (external ClickHouse 26.3, JDK 17, -Dprotocol=http, r2dbc-spi 1.0.0.RELEASE):
- 25 × full
R2DBCTestKitImplTest(32 tests) with 6 busy CPU loops → 0 failures. - 12 ×
R2DBCTestKitImplTest#batchpinned to a single CPU (taskset -c 0) with 8 busy CPU loops → 0 failures.
Total 37 local runs, 0 failures. CI runners are slower and more contended, which is consistent with the CI-only appearance. The job configuration itself notes thread pressure in this environment (build.yml: "http_client and apache_http_client do not work in CI environment (due to limited threads?)").
Expected Behaviour
batch completes deterministically. No request should be able to start after the connection that owns its HTTP connection manager has been closed.
Candidate mechanism (hypothesis — not proven)
batch is the only test in the class that runs two statements through one Batch, and the batch path executes them concurrently:
ClickHouseBatch.execute()(clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/ClickHouseBatch.java:32-38) maps the SQL list toMono.fromFuture(request::execute)over a single shared, mutableClickHouseRequest, thenflatMaps them —flatMapsubscribes inner sources concurrently (default concurrency 256), and the requests carryClickHouseClientOption.ASYNC = true(set inClickHouseConnection.createBatch()), so the actual POST runs on a client executor thread rather than the subscribing thread.ClickHouseConnection.close()(clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/connection/ClickHouseConnection.java:70-78) callsclient.close(), which closes that connection'sPoolingHttpClientConnectionManager.Flux.usingWhen(..., Connection::close)inTestKit.batchtriggers it as soon as the outerFluxterminates.
If the outer Flux can terminate while one of the two batch requests has been submitted to the executor but has not yet leased a connection, the close wins the race and that POST fails at LaxConnPool.lease — exactly the observed signature and the sub-100 ms failure time. This would make it a client-side race in product code, not test debt: an application closing an R2DBC connection right after a batch completes could see the same IllegalStateException instead of a clean completion.
We could not confirm this locally, so it is offered as a starting point only; no root cause is claimed. Note also #2976, a separate confirmed R2DBC connection-lifecycle defect in the same area.
Suggested direction
Make the batch's completion synchronize with all of its in-flight requests, so the connection cannot be closed while one is still starting (e.g. execute the batch statements sequentially with concatMap, or gate the connection close on the completion of every submitted request), instead of retrying or ignoring the failure in the test.
Configuration
Environment
- Cloud
- Client version:
main(0.10.0-rc1-SNAPSHOT) - Language version: JDK 17 (temurin)
- OS: ubuntu-latest (CI); Debian container (local attempt)
ClickHouse Server
- ClickHouse Server version: observed on
26.3and onlatest; not reproducible locally on 26.3 - Non-default settings: CI test fixtures (
users.d/users.xmlfrom the repo),custom_http_params=async_insert=0 - Tables involved: created by the r2dbc-spi
TestKit(CREATE TABLE test ( test_value INTEGER ) ENGINE = Memory)
Found by automated CI monitoring of our own PRs across unrelated runs, then verified by re-checking the run history and attempting a local reproduction; filed as CI-observed.
- 主要言語
- Java
- スター
- 1.6k
- フォーク
- 638
- 平均マージ
- 2日 46分
- マージ済み PR(30日)
- 46
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ClickHouse/clickhouse-java のほかの issue
-
[examples] Remove old Spring example対応中かも @polyglotAI-bot が 11 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
ClickHouse/clickhouse-java#3111 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug client-api-v2 test
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
ClickHouse/clickhouse-java#3076 ·
メンテナーはふだん 1 日以内に返信
-
area:sql-parser bug client-v1
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
ClickHouse/clickhouse-java#3066 ·
メンテナーはふだん 1 日以内に返信
-
bug client-api-v2 jdbc-v2
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
ClickHouse/clickhouse-java#2957 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug client-v1 wontfix
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ClickHouse/clickhouse-java#2895 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
ClickHouse/clickhouse-java の issue をすべて見る
似ている issue
-
[destination-snowflake] Custom domains rejected unlike source connections対応中かも @kuza55 が今日担当しました。 オープンautoteam community connectors/destination/snowflake team/use
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
area-dashboard
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
component/operate kind/feature-request
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Forge coverage prompts carry text the agent cannot act on対応中かも @graalvmbot が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
oracle/graalvm-reachability-metadata#10572 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
IBM/sample-app-mod#55 ·