The health check ping inside the pgxpool.Acquire loop uses the context from the Acquire call itself.
If a connection in the pool becomes unresponsive (e.g., due to a network partition where packets are dropped silently), the ping can block for a very long time, often until the OS TCP timeout. This can cause the application to hang on a single bad connection, even if other healthy connections are available.
A dedicated, short timeout for this internal health check would allow the pool to quickly identify and discard bad connections, making it more resilient.
I have prepared a PR to address this by adding an optional PingTimeout to pgxpool.Config:
I create a separate context from parentContext to use in the Ping(ctx) with timeout (if not 0).
#2393
I wanted to check the solution before finalizing implemetation, i.e. adding tests, etc.
The health check
pinginside thepgxpool.Acquireloop uses the context from theAcquirecall itself.If a connection in the pool becomes unresponsive (e.g., due to a network partition where packets are dropped silently), the
pingcan block for a very long time, often until the OS TCP timeout. This can cause the application to hang on a single bad connection, even if other healthy connections are available.A dedicated, short timeout for this internal health check would allow the pool to quickly identify and discard bad connections, making it more resilient.
I have prepared a PR to address this by adding an optional
PingTimeouttopgxpool.Config:I create a separate context from parentContext to use in the
Ping(ctx)with timeout (if not 0).#2393
I wanted to check the solution before finalizing implemetation, i.e. adding tests, etc.