fix(agent): Retry Docker check on non-200 HTTP response (#1754)

The previous behavior only caught some errors including inaccessible
hosts, but not others like failed authentication or service
unavailability. This largely applies when using a socket proxy and
having the retry mitigates some erroneous behavior.
This commit is contained in:
Elio Di Nino
2026-02-18 10:42:58 -08:00
committed by GitHub
parent 10d853c004
commit ef92b254bf
2 changed files with 122 additions and 3 deletions

View File

@@ -594,18 +594,22 @@ func (dm *dockerManager) checkDockerVersion() {
const versionMaxTries = 2
for i := 1; i <= versionMaxTries; i++ {
resp, err = dm.client.Get("http://localhost/version")
if err == nil {
if err == nil && resp.StatusCode == http.StatusOK {
break
}
if resp != nil {
resp.Body.Close()
}
if i < versionMaxTries {
slog.Debug("Failed to get Docker version; retrying", "attempt", i, "error", err)
if err != nil {
slog.Debug("Failed to get Docker version; retrying", "attempt", i, "error", err)
} else {
slog.Debug("Failed to get Docker version; retrying", "attempt", i, "status code", resp.StatusCode)
}
time.Sleep(5 * time.Second)
}
}
if err != nil {
if err != nil || resp.StatusCode != http.StatusOK {
return
}
if err := dm.decode(resp, &versionInfo); err != nil {