Skip to content

lib/upgrade: HTTP response body leak in FetchLatestReleases on non-2xx status #10635

Closed

Description

@mango766

Description

In lib/upgrade/upgrade_supported.go, the FetchLatestReleases function has a response body leak when the server returns a non-2xx HTTP status code.

func FetchLatestReleases(releasesURL, current string) []Release {
    resp, err := upgradeClientGet(releasesURL, current)
    if err != nil {
        ...
        return nil
    }
    if resp.StatusCode > 299 {
        slog.Warn("Failed to fetch latest release information", slogutil.Error(resp.Status))
        return nil  // <-- resp.Body is never closed here
    }
    ...
    resp.Body.Close()
    return rels
}

When the response status code is > 299 (e.g. 429 Too Many Requests, 503 Service Unavailable), the function returns nil without calling resp.Body.Close(). According to the Go net/http docs, the caller must close the response body to allow the underlying TCP connection to be reused by the HTTP client's connection pool. Failing to do so leaks a goroutine and the connection until the GC eventually finalizes it.

Impact

  • HTTP connection pool connections are not reused after a failed release check, slowly exhausting available connections under load or on flaky networks.
  • Goroutines associated with the response body may be leaked briefly.

Fix

Add defer resp.Body.Close() immediately after the successful Do() call and remove the later explicit close, so all return paths are covered.

resp, err := upgradeClientGet(releasesURL, current)
if err != nil {
    ...
    return nil
}
defer resp.Body.Close()

if resp.StatusCode > 299 {
    ...
    return nil
}

Activity

  1. added a commit that references this issue on Apr 22, 2026
    b1ccf3f
  2. added a commit that references this issue on Jun 28, 2026
    a4dadaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions