ClickHouse / ClickHouse/clickhouse-java

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

Ouverte
#1,712 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
area:network bug triaged usability
Langage dominant
Java
Étoiles
1.6k
Forks
636
Merge moyen
2 j 23 h
PR mergées (30 j)
29

Description

### 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?

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par suivre ClickHouseClient.read(...).execute() et le chemin await de la coroutine utilisé dans l’exemple, puis examinez comment ClickHouseHttpOption.MAX_OPEN_CONNECTIONS et response.close() sont gérés lors de l’annulation. Reproduisez les requêtes annulées et déterminez le comportement attendu concernant le nettoyage de la connexion et de la requête côté serveur.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
kotlin, spring-boot
Domaine
backend, databases
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.