ch-go icon indicating copy to clipboard operation
ch-go copied to clipboard

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

Open danieloliveira-shopify opened this issue 9 months ago • 2 comments

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 avatar Mar 25 '25 11:03 danieloliveira-shopify

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 25 '25 11:03 CLAassistant

@danieloliveira-shopify Make sure to complete the CLA in the above message

SpencerTorres avatar Apr 01 '25 03:04 SpencerTorres