Skip to content

pgxpool Acquire can hang on unresponsive connections during health check ping #2394

Description

@amirsalarsafaei

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions