Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion api/utils/retryutils/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type LinearConfig struct {
AutoReset int64
// Clock to override clock in tests
Clock clockwork.Clock
// BeforeRetry is called before the failing function is retried. If unset,
// a debug log will be emitted.
BeforeRetry func(ctx context.Context, err error, wait time.Duration, attempt int64)
}

// CheckAndSetDefaults checks and sets defaults
Expand Down Expand Up @@ -190,7 +193,12 @@ func (r *Linear) For(ctx context.Context, retryFn func() error) error {
if errors.As(trace.Unwrap(err), &permanentRetryError) {
return trace.Wrap(err)
}
slog.DebugContext(ctx, "Waiting to retry operation again", "wait", r.Duration().String(), "error", err)
wait := r.Duration()
if r.BeforeRetry == nil {
slog.DebugContext(ctx, "Waiting to retry operation again", "wait", wait.String(), "error", err)
} else {
r.BeforeRetry(ctx, err, wait, r.attempt)
}
Copy link
Contributor

@rosstimothy rosstimothy Jan 9, 2026

Choose a reason for hiding this comment

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

Would this be less scary/noisy if we didn't include the stack trace? Can we remove the callback and always unwrap the error instead?

		slog.DebugContext(ctx, "Waiting to retry operation again", "wait", r.Duration().String(), "error", trace.Unwrap(err))

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah - I think removing the stack trace makes this much less visually disruptive.

select {
case <-r.After():
r.Inc()
Expand Down
10 changes: 10 additions & 0 deletions lib/auth/machineid/machineidv1/auto_update_version_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package machineidv1
import (
"context"
"log/slog"
"strings"
"sync"
"time"

Expand All @@ -29,6 +30,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
machineidv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
Expand Down Expand Up @@ -180,6 +182,14 @@ func (r *AutoUpdateVersionReporter) runLeader(ctx context.Context) error {
Step: 30 * time.Second,
Max: 1 * time.Minute,
Jitter: retryutils.DefaultJitter,
BeforeRetry: func(ctx context.Context, err error, wait time.Duration, attempt int64) {
// Silence noisy log from failing to acquire semaphore
// when it is already held by another auth server.
if strings.Contains(err.Error(), constants.MaxLeases) {
return
}
r.logger.DebugContext(ctx, "Waiting to retry operation again", "wait", wait.String(), "error", err)
},
},
},
)
Expand Down
Loading