Skip to content

Modern Docker Management, Designed for Everyone

fix: don't overwrite good image update records on registry rate-limit errors (#3190)

Kyle Mendell8861564f0da4
diff --git a/backend/internal/services/container_registry_service.go b/backend/internal/services/container_registry_service.go
index 69101e965..335a960d4 100644
--- a/backend/internal/services/container_registry_service.go
+++ b/backend/internal/services/container_registry_service.go
@@ -1328,7 +1328,11 @@ func isRateLimitErrorInternal(err error) bool {
if err == nil {
return false
}
- errLower := strings.ToLower(err.Error())
+ return isRateLimitErrorStringInternal(err.Error())
+}
+
+func isRateLimitErrorStringInternal(msg string) bool {
+ msgLower := strings.ToLower(msg)
indicators := []string{
"toomanyrequests",
"rate limit",
@@ -1338,7 +1342,7 @@ func isRateLimitErrorInternal(err error) bool {
"retry-after",
}
for _, indicator := range indicators {
- if strings.Contains(errLower, indicator) {
+ if strings.Contains(msgLower, indicator) {
return true
}
}
diff --git a/backend/internal/services/image_update_service.go b/backend/internal/services/image_update_service.go
index bfb6eecda..4ea810bcd 100644
--- a/backend/internal/services/image_update_service.go
+++ b/backend/internal/services/image_update_service.go
@@ -866,7 +866,20 @@ func savePreparedUpdateResultWithTxInternal(tx *gorm.DB, imageID, repo, tag stri
// Check if there's an existing record to compare state changes
var existingRecord models.ImageUpdateRecord
- if err := tx.Where("id = ?", imageID).First(&existingRecord).Error; err == nil {
+ hasExisting := tx.Where("id = ?", imageID).First(&existingRecord).Error == nil
+
+ // A registry rate limit (429) is transient: keep the previous good result
+ // instead of clobbering it with an error record
+ if hasExisting &&
+ strings.TrimSpace(result.Error) != "" &&
+ isRateLimitErrorStringInternal(result.Error) &&
+ strings.TrimSpace(stringPtrToString(existingRecord.LastError)) == "" {
+ slog.Debug("Preserving previous image update result; check hit a registry rate limit",
+ "imageID", imageID, "repository", repo, "tag", tag, "error", result.Error)
+ return nil
+ }
+
+ if hasExisting {
// Existing record found - check if we need to reset notification_sent
stateChanged := existingRecord.HasUpdate != updateRecord.HasUpdate
digestChanged := stringPtrToString(existingRecord.LatestDigest) != stringPtrToString(updateRecord.LatestDigest)
diff --git a/backend/internal/services/image_update_service_test.go b/backend/internal/services/image_update_service_test.go
index f63597d7f..fb72dfd51 100644
--- a/backend/internal/services/image_update_service_test.go
+++ b/backend/internal/services/image_update_service_test.go
@@ -1188,6 +1188,68 @@ func TestImageUpdateService_NotificationSentReset(t *testing.T) {
}
}
+func TestImageUpdateService_RateLimitErrorPreservesPreviousResult(t *testing.T) {
+ db := setupImageUpdateTestDB(t)
+
+ imageID := "sha256:ratelimit1"
+ repo := "docker.io/library/nginx"
+ tag := "latest"
+ checkTime := time.Now().Add(-1 * time.Hour).UTC().Truncate(time.Second)
+
+ tests := []struct {
+ name string
+ resultError string
+ expectPreserved bool
+ }{
+ {
+ name: "rate limit error preserves previous good record",
+ resultError: "registry manifest inspect failed for docker.io/library/nginx:latest: manifest request failed with status: 429",
+ expectPreserved: true,
+ },
+ {
+ name: "non-rate-limit error overwrites previous good record",
+ resultError: "registry manifest inspect failed for docker.io/library/nginx:latest: manifest unknown",
+ expectPreserved: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ db.Exec("DELETE FROM image_updates WHERE id = ?", imageID)
+
+ existing := &models.ImageUpdateRecord{
+ ID: imageID,
+ Repository: repo,
+ Tag: tag,
+ HasUpdate: false,
+ CurrentVersion: tag,
+ CurrentDigest: stringToPtr("sha256:current"),
+ LatestDigest: stringToPtr("sha256:current"),
+ CheckTime: checkTime,
+ }
+ require.NoError(t, db.Create(existing).Error)
+
+ result := &imageupdate.Response{
+ Error: tt.resultError,
+ CheckTime: time.Now(),
+ }
+ require.NoError(t, savePreparedUpdateResultWithTxInternal(db.DB, imageID, repo, tag, result))
+
+ var saved models.ImageUpdateRecord
+ require.NoError(t, db.First(&saved, "id = ?", imageID).Error)
+
+ if tt.expectPreserved {
+ assert.Nil(t, saved.LastError, "previous good record should be preserved")
+ assert.Equal(t, "sha256:current", stringPtrToString(saved.LatestDigest))
+ assert.Equal(t, checkTime, saved.CheckTime.UTC())
+ } else {
+ assert.Equal(t, tt.resultError, stringPtrToString(saved.LastError))
+ assert.Nil(t, saved.LatestDigest)
+ }
+ })
+ }
+}
+
// TestGetUnnotifiedUpdates tests retrieving updates that haven't been notified
func TestImageUpdateService_GetUnnotifiedUpdates(t *testing.T) {
ctx := context.Background()