ClickHouse / ClickHouse/clickhouse-java

clickhouse-http-client: how do I close the connection in case of an error?

オープン
#1,712 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
area:network bug triaged usability
主要言語
Java
スター
1.6k
フォーク
636
平均マージ
2日 23時間
マージ済み PR(30日)
29

説明

### When the client cancels the request, the connection to the asynchronous request is not closed

I use **spring-boot** in combination with **clickhouse-http-client** and **Kotlin**
Library Version: **com.clickhouse:clickhouse-http-client:0.6.1**

### Steps to reproduce
1. If the client sends 10 read requests and cancels them, the limit in **max_open_connections** (ClickHouseHttpOption.MAX_OPEN_CONNECTIONS) will be reached, because, in fact, the connection will not be closed by anyone.

### Code example
```kotlin
package com.api.test

import com.clickhouse.client.ClickHouseClient
import com.clickhouse.client.ClickHouseNode
import com.clickhouse.data.ClickHouseFormat
import kotlinx.coroutines.future.await
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import kotlin.coroutines.cancellation.CancellationException

@RestController
@RequestMapping("/test")
class TestApi(
private val clickHouseClient: ClickHouseClient,
private val clickhouseNode: ClickHouseNode,
) {
private val logger = LoggerFactory.getLogger(TestApi::class.java)

@GetMapping("/read")
suspend fun read() {
try {
val response = clickHouseClient.read(clickhouseNode)
.format(ClickHouseFormat.JSON)
.query("""SELECT sleep(3)""".trimIndent())
.execute()
.await()
response.close()
} catch (e: CancellationException) {
logger.error("Error", e)
// How do I close the connection?
}
}
}
```

### Question
ClickHouse has the **cancel_http_readonly_queries_on_client_close** option. But how can I use the library to initiate connection closure instead of waiting for a response? Or maybe I can cancel a previously sent request?

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、ClickHouseClient.read(...).execute() と、例で使用されている coroutine の await パスを追跡し、次にキャンセル時に ClickHouseHttpOption.MAX_OPEN_CONNECTIONS と response.close() がどのように処理されるかを調べます。キャンセルされたリクエストを再現し、接続とサーバークエリのクリーンアップで期待される動作を特定します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
kotlin, spring-boot
領域
backend, databases
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。