ClickHouse / ClickHouse/ch-go

feat[pool]: Expose Close method to facilitate removal of broken connections

Open
#1,053 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
428
Forks
84
Avg merge
9d 6h
Merged PRs (30d)
4

Description

Expose `Close` method to allow connections to be closed if they are in a bad state.

There are situations were the acquired connection is in a broken state but there is no explicitly way to either remove it from the pool or close it.

As a package user I want to have the choice to close and destroy a broken connection.

The `backgroundHealthCheck` does not check for connection's state therefore it does not remove broken connections.

The snippet below exemplifies how I would use the Close method. After checking the connection state using Ping I can close/destroy in case of an error.

```go
conn, err := pool.Acquire(ctx)
if err != nil {
return nil, err
}

if err := conn.Ping(ctx); err != nil {
conn.Close() <<<<< This connections is broken and should not be put back into the pool using conn.Release()
return nil, level.Error(logger).Log("msg", "failed to ping acquired connection from pool", "err", err)
}

return conn, nil
```

Please let me know if there is an alternative way of getting the same behaviour.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.