PostgreSQL reconnect retry interval should be configurable
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 failedapproximately 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!
Source: drogonframework/drogon