ch-go
ch-go copied to clipboard
feat[pool]: Expose Close method to facilitate removal of broken connections
Summary
This adds a Close method to the chpool.Client struct. This function will close the underlying connection and destroy the resource from the pool.
This will allow broken connections to not be put back into the pool if they are broken. The snipped below exemplifies the scenario.
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
Checklist
Delete items not relevant to your PR:
- [ ] Unit and integration tests covering the common scenarios were added
- [ ] A human-readable description of the changes was provided to include in CHANGELOG
- [ ] For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials
@danieloliveira-shopify Make sure to complete the CLA in the above message