You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @mgutz do you think you could make MustPing receive an optional parameter (with ...) to specify a timeout?
The issue I'm trying to avoid is that upon launching my servers, if there's no connectivity to a database, they'll just stay there trying indefinitely to connect, silently. The behavior I would expect of a well-behaved server is to fail with the proper error ("Could not connect to database at somethingsomething:3845" or something like that). That would trigger our error handling infrastructure and we'd be notified.
Do you think this is something you'd like to support? I can contribute with a PR if you'd like.
The text was updated successfully, but these errors were encountered:
I totally agree, the problem here is not that it won't panic (although I will send a PR with ShouldPing as I'd rather have that). The problem here is that it will never panic. It will just keep retrying time after time to ping.
I looked at the backoff lib and it has a MaxElapsedTime property that can be used for this purpose, like:
func shouldPing(db *sql.DB, timeout time.Duration) error {
var err error
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = timeout
ticker := backoff.NewTicker(b)
// Ticks will continue to arrive when the previous operation is still running,
// so operations that take a while to fail could run in quick succession.
for range ticker.C {
if err = db.Ping(); err != nil {
continue
}
ticker.Stop()
return nil
}
return fmt.Errorf("Could not ping database!")
}
Hey @mgutz do you think you could make MustPing receive an optional parameter (with ...) to specify a timeout?
The issue I'm trying to avoid is that upon launching my servers, if there's no connectivity to a database, they'll just stay there trying indefinitely to connect, silently. The behavior I would expect of a well-behaved server is to fail with the proper error ("Could not connect to database at somethingsomething:3845" or something like that). That would trigger our error handling infrastructure and we'd be notified.
Do you think this is something you'd like to support? I can contribute with a PR if you'd like.
The text was updated successfully, but these errors were encountered: