Log first database connection error while retrying

This commit is contained in:
Eric Lippmann 2021-05-21 15:23:42 +02:00
parent 44c734f72d
commit be3180a54c

View file

@ -12,6 +12,7 @@ import (
"log"
"net"
"os"
"sync"
"syscall"
"time"
)
@ -26,10 +27,16 @@ type Driver struct {
// TODO(el): Test DNS.
func (d Driver) Open(dsn string) (c driver.Conn, err error) {
var logFirstError sync.Once
err = retry.WithBackoff(
context.Background(),
func(context.Context) (err error) {
c, err = d.Driver.Open(dsn)
logFirstError.Do(func() {
if err != nil {
d.Logger.Warnw("Can't connect to database. Retrying", zap.Error(err))
}
})
return
},
shouldRetry,