Skip to content
Merged
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
11 changes: 10 additions & 1 deletion integrations/access/common/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (a *BaseApp) updateMessages(ctx context.Context, reqID string, tag pd.Resol

// If resolution field is not empty then we already resolved the incident before. In this case we just quit.
if existing.AccessRequestData.ResolutionTag != pd.Unresolved {
return GenericPluginData{}, trace.CompareFailed("request is already resolved")
return GenericPluginData{}, trace.AlreadyExists("request is already resolved")
}

// Mark plugin data as resolved.
Expand All @@ -432,6 +432,15 @@ func (a *BaseApp) updateMessages(ctx context.Context, reqID string, tag pd.Resol
log.Debug("Failed to update messages: plugin data is missing")
return nil
}
if trace.IsAlreadyExists(err) {
if tag != pluginData.ResolutionTag {
return trace.WrapWithMessage(err,
"cannot change the resolution tag of an already resolved request, existing: %s, event: %s",
pluginData.ResolutionTag, tag)
}
log.Debug("Request is already resolved, ignoring event")
return nil
}
if err != nil {
return trace.Wrap(err)
}
Expand Down
6 changes: 4 additions & 2 deletions integrations/lib/plugindata/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func (c *CompareAndSwap[T]) Create(
// Update tries to perform compare-and-swap update of a plugin data assuming that it exist
//
// modifyT will receive existing plugin data and should return a modified version of the data.

//
// If existing plugin data does not match expected data, then a trace.CompareFailed error should
// be returned to backoff and try again.

//
// To abort the update, modifyT should return an error other, than trace.CompareFailed, which
// will be propagated back to the caller of `Update`.
func (c *CompareAndSwap[T]) Update(
Expand All @@ -131,6 +131,7 @@ func (c *CompareAndSwap[T]) Update(
if trace.IsCompareFailed(err) {
failedAttempts = append(failedAttempts, trace.Wrap(err))
backoffErr := backoff.Do(ctx)
// backoffErr is not nil when the context has expired and we must return
if backoffErr != nil {
failedAttempts = append(failedAttempts, trace.Wrap(backoffErr))
return emptyData, trace.NewAggregate(failedAttempts...)
Expand All @@ -152,6 +153,7 @@ func (c *CompareAndSwap[T]) Update(
// A conflict happened, we register the failed attempt and wait before retrying
failedAttempts = append(failedAttempts, trace.Wrap(err))
backoffErr := backoff.Do(ctx)
// backoffErr is not nil when the context has expired and we must return
if backoffErr != nil {
failedAttempts = append(failedAttempts, trace.Wrap(backoffErr))
return emptyData, trace.NewAggregate(failedAttempts...)
Expand Down