Skip to content

PostgreSQL reconnect retry interval should be configurable #2581

Description

@AhmadPayamani

Description

When a PostgreSQL connection is lost, Drogon automatically attempts to
reconnect every 1 second.

This can cause unnecessary CPU usage, connection attempts, and excessive
logs when PostgreSQL is unavailable for an extended period.

I am using Drogon v1.9.13.

Current behavior

In orm_lib/src/DbClientImpl.cc, the reconnect is scheduled with:

loop->runAfter(1, [weakPtr, loop, closeConnPtr] {
    ...
});

As a result, when PostgreSQL is down, I see logs like:

Pg connection failed
Pg connection failed
Pg connection failed
Pg connection failed

approximately every second for each connection in the pool.

Expected behavior

It would be useful to have a configurable reconnect interval, for example:

"reconnect_interval": 5

The default could remain 1 second for backward compatibility.

Suggested implementation

Instead of hard-coding:

 loop->runAfter(1, [weakPtr, loop, closeConnPtr] {
    ...
});

the reconnect delay could be stored in the database client configuration:

loop->runAfter(reconnectInterval, [weakPtr, loop, closeConnPtr] {
    ...
});

This would allow applications with unstable or remote PostgreSQL servers to
use a more appropriate retry interval.

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions