pgxpool: different MaxConnLifetime for fallback hosts
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
**Is your feature request related to a problem? Please describe.**
Multihost (HA) fallbacks might not be an equal option to make a connection to. When used as a true fallbacks, app might prefer to use them only as long as "primary" host remains unavailable. One way to achieve it is to lower `MaxConnLifetime` for connections established to fallback hosts: they will be closed more often and reconnection attempt will try primary host first.
**Describe the solution you'd like**
Minimal implementation would be to introduce `pool_fallback_max_conn_lifetime` (as well as the rest of pool configs probably) and then wire it up to be respected by `pgxpool`. Because fallbacks are at the connection level, pool might need a way to inspect which host was actually used to establish connection if it is not available already.
**Alternative implementations**
Probably something can be cobbled up together with `pgxpool.Config.AfterConnect` and `AfterRelease` to implement tracking which connections was established to which hosts (assuming host info is available somewhere in the `Conn`) and then returning `false` from `AfterRelease` for connections to fallback which exceeded lifetime intended for fallback connections. It is not pretty and requires reimplementing connection age tracking done by pgxpool already.
Contributor guide
Research direction
Start by reading the pgxpool configuration and connection lifecycle, especially Config.AfterConnect, AfterRelease, and the Conn host information mentioned in the issue. Determine how fallback hosts are identified and how connection lifetime is currently tracked; done means a pool configuration can apply a distinct lifetime to fallback connections and the behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100