Skip to content

bug: Artifact Hub sync fails (429 errors) and leaks connections #855

@parthivsaikia

Description

@parthivsaikia

Current Behavior

The GetAllAhHelmPackages function in utils/artifacthub.go has two main problems:

  1. No Rate Limiting: The code hits the Artifact Hub API too fast. When it receives a 429 Too Many Requests error, it fails immediately instead of waiting and trying again.
  2. Memory Leak: It uses defer resp.Body.Close() inside a for loop. In Go, defer waits for the function to finish, not the loop. This keeps thousands of connections open at the same time, wasting memory.

Expected Behavior

  1. Handle 429s: The code should sleep and retry if it hits a rate limit (exponential backoff).
  2. Fix Leak: The response body should be closed immediately after each loop iteration, not at the end of the function.

Screenshots/Logs

The code pattern causing the leak:

for _, p := range res {
    // ...
    resp, err := http.Get(url)
    // ...
    defer resp.Body.Close() // <--- Bad: This waits until the whole function is done
    // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/staleIssue has not had any activity for an extended period of timekind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions