Skip to content

fix: add connect_timeout and ping timeout to database connections#293

Merged
tianzhou merged 1 commit intomainfrom
fix/connect-timeout
Feb 16, 2026
Merged

fix: add connect_timeout and ping timeout to database connections#293
tianzhou merged 1 commit intomainfrom
fix/connect-timeout

Conversation

@tianzhou
Copy link
Contributor

@tianzhou tianzhou commented Feb 16, 2026

Prevents indefinite hangs when the target database is unreachable by:

  • Adding connect_timeout=30 to the DSN for TCP-level timeout
  • Using PingContext with a 30s timeout instead of bare Ping()

Prevents indefinite hangs when the target database is unreachable by:
- Adding connect_timeout=10 to the DSN for TCP-level timeout
- Using PingContext with a 10s timeout instead of bare Ping()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 16, 2026 14:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds timeout configurations to database connections to prevent indefinite hangs when the target database is unreachable. The changes implement two timeout mechanisms: a TCP-level connection timeout via the connect_timeout DSN parameter, and a ping timeout using PingContext with a timeout context.

Changes:

  • Added time package import to support timeout configuration
  • Modified Connect function to use PingContext with a 30-second timeout instead of bare Ping()
  • Updated buildDSN function to include connect_timeout=30 parameter in the connection string

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Test the connection
if err := conn.Ping(); err != nil {
// Test the connection with a timeout to fail fast if the database is unreachable
pingCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ping timeout is set to 30 seconds, but the PR description states it should be 10 seconds. This timeout value should match the PR description to ensure consistency with the stated goal of preventing indefinite hangs.

Copilot uses AI. Check for mistakes.
@tianzhou tianzhou merged commit 96fe594 into main Feb 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant