Current Behavior
The GetAllAhHelmPackages function in utils/artifacthub.go has two main problems:
- 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.
- 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
- Handle 429s: The code should sleep and retry if it hits a rate limit (exponential backoff).
- 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
// ...
}
Current Behavior
The
GetAllAhHelmPackagesfunction inutils/artifacthub.gohas two main problems:429 Too Many Requestserror, it fails immediately instead of waiting and trying again.defer resp.Body.Close()inside aforloop. In Go,deferwaits for the function to finish, not the loop. This keeps thousands of connections open at the same time, wasting memory.Expected Behavior
Screenshots/Logs
The code pattern causing the leak: