feat[pool]: Expose Close method to facilitate removal of broken connections
- 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.