feat: add connect_timeout and pgx multi-host failover for database resilience #24
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!24
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/db-connect-timeout-failover"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
CONNECT_TIMEOUTdatabase setting (default 10s) injected into PostgreSQL connection strings as pgx'sconnect_timeoutparameter. This ensures connections to unreachable hosts fail fast instead of waiting for the OS TCP timeout (~127s).HOST_REPLICAhandling to combine all replica hosts into a single pgx multi-host connection string instead of creating separate xorm Engines per host. Previously, if any listed replica host was unreachable, xorm's load balancer could route queries to the dead Engine, causing hangs. Now pgx handles failover transparently.HOST_PRIMARYalready supported pgx multi-host; theconnect_timeoutnow ensures fast failover there too.Context
When a database node goes down, Forgejo's connection attempts hang for ~127 seconds (OS TCP SYN retry timeout) per unreachable host. With multiple HAProxy endpoints listed for primary/replica connections, a single dead node blocks startup and causes query failures.
With these changes, worst-case failover takes ~10 seconds per unreachable host instead of ~127 seconds, and HAProxy handles load balancing across actual PostgreSQL nodes.