Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return error if not nil when connecting #151

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ func (c *Connector) connectWithRetries(ctx context.Context, conn dbConnection, k
applyHeaders(q, headers)
}

var db *sql.DB
var err error
for i := 0; i < c.driverSettings.Retries; i++ {
db, err := c.Reconnect(ctx, conn, q, key)
db, err = c.Reconnect(ctx, conn, q, key)
if err != nil {
return err
}
Expand All @@ -74,20 +76,24 @@ func (c *Connector) connectWithRetries(ctx context.Context, conn dbConnection, k
}
err = c.connect(conn)
if err == nil {
return err
break
}

if !shouldRetry(c.driverSettings.RetryOn, err.Error()) {
break
}

if i+1 == c.driverSettings.Retries {
break
}

if c.driverSettings.Pause > 0 {
time.Sleep(time.Duration(c.driverSettings.Pause * int(time.Second)))
}
backend.Logger.Warn(fmt.Sprintf("connect failed: %s. Retrying %d times", err.Error(), i))
backend.Logger.Warn(fmt.Sprintf("connect failed: %s. Retrying %d times", err.Error(), i+1))
}

return nil
return err
}

func (c *Connector) connect(conn dbConnection) error {
Expand Down
Loading