Skip to content

Commit 5745c64

Browse files
mirkoCrobumirkoCrobu
andauthored
improve retry for upgrade operations
Co-authored-by: mirkoCrobu <mirkocrobu@NB-0531.localdomain>
1 parent 808948e commit 5745c64

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

internal/orchestrator/system.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func pullImage(ctx context.Context, stdout io.Writer, docker dockerClient.APICli
7676
}
7777
allErr = errors.Join(allErr, lastErr)
7878

79-
if !strings.Contains(lastErr.Error(), "toomanyrequests") {
79+
if !isTemporaryDockerError(lastErr) {
8080
return allErr // Non-retryable error
8181
}
8282

@@ -119,6 +119,21 @@ func pullImage(ctx context.Context, stdout io.Writer, docker dockerClient.APICli
119119
}
120120
return nil
121121
}
122+
func isTemporaryDockerError(err error) bool {
123+
errorString := err.Error()
124+
transientSubstrings := []string{
125+
"toomanyrequests",
126+
"Client.Timeout exceeded",
127+
"request canceled while waiting for connection",
128+
}
129+
130+
for _, sub := range transientSubstrings {
131+
if strings.Contains(errorString, sub) {
132+
return true
133+
}
134+
}
135+
return false
136+
}
122137

123138
// List of prefixes used to identify current or past Arduino images. Used both during 'system init' and during cleanup.
124139
var imagePrefixes = []string{"ghcr.io/bcmi-labs/", "public.ecr.aws/arduino/", "ghcr.io/arduino/", "influxdb"}

internal/update/apt/service.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,15 @@ func runUpdateCommand(ctx context.Context) error {
176176

177177
func runUpgradeCommand(ctx context.Context, names []string) iter.Seq2[string, error] {
178178
env := []string{"NEEDRESTART_MODE=l"}
179-
args := append([]string{"sudo", "apt-get", "install", "--only-upgrade", "-y"}, names...)
179+
180+
aptOptions := []string{
181+
"-o", "Acquire::Retries=3",
182+
"-o", "Acquire::http::Timeout=30",
183+
"-o", "Acquire::https::Timeout=30",
184+
}
185+
args := []string{"sudo", "apt-get", "install", "--only-upgrade", "-y"}
186+
args = append(args, aptOptions...)
187+
args = append(args, names...)
180188

181189
return func(yield func(string, error) bool) {
182190
upgradeCmd, err := paths.NewProcess(env, args...)

0 commit comments

Comments
 (0)