-
Notifications
You must be signed in to change notification settings - Fork 170
fix: handle rate limits and resource leaks in Artifact Hub sync #856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: PARTHIV PRATIM SAIKIA <[email protected]>
Summary of ChangesHello @parthivsaikia, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the stability and reliability of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses the rate limiting and resource leak issues in GetAllAhHelmPackages. The introduction of exponential backoff is a solid improvement over a static sleep, and the resource leak from defer inside a loop is correctly fixed. My review includes a few suggestions to further improve robustness and maintainability: one critical fix for potential panics from unsafe type assertions, and recommendations to replace fmt.Println with proper logging and to use a constant for the retry count.
| name := p["name"].(string) | ||
| repo := p["repository"].(map[string]interface{})["name"].(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These direct type assertions can cause a panic if the fields name or repository are missing from the API response, or if their types are not what's expected. This could crash the entire sync process.
It's much safer to use the two-value comma-ok idiom to check for success before using the value. For example:
name, ok := p["name"].(string)
if !ok {
log.Printf("Skipping package due to missing or invalid name: %v", p)
continue
}
repoMap, ok := p["repository"].(map[string]interface{})
if !ok {
log.Printf("Skipping package due to missing or invalid repository: %v", p)
continue
}
repo, ok := repoMap["name"].(string)
if !ok {
log.Printf("Skipping package due to missing or invalid repository name: %v", p)
continue
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot implement this feedback.
| var resp *http.Response | ||
| var err error | ||
|
|
||
| for i := 0; i < 5; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
|
|
||
| if err != nil { | ||
| fmt.Println(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using fmt.Println for errors is not recommended in library code as it writes to standard output and offers no configurability (like levels, formatting, or output destination). This makes debugging in a larger application difficult. This applies to all fmt.Println calls in this function.
Consider using a structured logger. The project seems to use logrus elsewhere, but even the standard log package would be an improvement. For example:
import "log"
// ...
log.Printf("error during http get for url %s: %v", url, err)
Description
This PR addresses critical stability issues identified in the
GetAllAhHelmPackagesfunction during high-volume syncs with Artifact Hub.Changes included:
429 Too Many Requestserrors gracefully.defer resp.Body.Close()was placed inside aforloop (which only closes resources on function return). The response body is now closed explicitly after each iteration.This PR fixes #855
Signed commits