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

retry: distinguish non-retryable errors from timeouts #719

Closed
wants to merge 1 commit into from
Closed
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: 12 additions & 2 deletions pkg/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package retry
import (
"context"
"database/sql/driver"
"fmt"
"github.com/go-sql-driver/mysql"
"github.com/icinga/icingadb/pkg/backoff"
"github.com/lib/pq"
Expand Down Expand Up @@ -65,7 +66,7 @@ func WithBackoff(
}

if !isRetryable {
err = errors.Wrap(err, "can't retry")
err = errors.Wrap(err, "can't retry non-retryable error")

return
}
Expand All @@ -76,10 +77,19 @@ func WithBackoff(
if outerErr := parentCtx.Err(); outerErr != nil {
err = errors.Wrap(outerErr, "outer context canceled")
} else {
var errMsg string
if errors.Is(ctx.Err(), context.DeadlineExceeded) && settings.Timeout > 0 {
errMsg = fmt.Sprintf("can't retry as timeout of %v has been exceeded", settings.Timeout)
} else {
// This shouldn't happen as the context should either be the parentCtx or be
// wrapped as context.WithTimeout. However, just to be future-proof...
errMsg = "can't retry as subcontext is canceled"
}

if err == nil {
err = ctx.Err()
}
err = errors.Wrap(err, "can't retry")
err = errors.Wrap(err, errMsg)
}

return
Expand Down
Loading