fix: Exit initializer analysis on context cancel#10003
fix: Exit initializer analysis on context cancel#10003liamdalg wants to merge 1 commit intoGoogleContainerTools:mainfrom
Conversation
- Pass parent context down to analyzers - Check for ctx.Err() before recursing subdirectories or analyzing files. Running skaffold init in a directory with a large number of files can take an extremely long time as it crawls and analyzes all subdirectories. Previously, the use of context.Background() prevented signals (e.g. the user pressing CTRL-C) from cancelling the operation.
Summary of ChangesHello, 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 improves the user experience for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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.
Code Review
This pull request addresses an important usability issue by making the initializer analysis cancellable. The changes correctly propagate the context down through the initializer package and add checks for cancellation. This will prevent skaffold from hanging when run in large directories. I've added one suggestion to further improve the responsiveness of the cancellation.
| for _, subdir := range subdirectories { | ||
| if err := a.Analyze(subdir); err != nil { | ||
| if err := a.Analyze(ctx, subdir); err != nil { | ||
| return err | ||
| } | ||
| } |
There was a problem hiding this comment.
To improve responsiveness to cancellation, it's good practice to check if the context is done inside loops that might have many iterations. While the recursive call to Analyze checks the context at the beginning, adding a check here before the call will make cancellation more immediate if there are many subdirectories to process.
for _, subdir := range subdirectories {
if err := ctx.Err(); err != nil {
return err
}
if err := a.Analyze(ctx, subdir); err != nil {
return err
}
}
Description
Running skaffold init in a directory with a large number of files can take an extremely long time as it crawls and analyzes all subdirectories. The use of
context.Background()means that it is not derived from the top-level context, and signals (e.g. the user pressing CTRL-C) cannot cancel the operation.This has caused issues for me when accidentally running e.g.
skaffold devin the wrong directory, which falls back toinit.I've added in a
context.Contextparam where appropriate in theinitializerpackage, and checkedctx.Err()when iterating over analyzers in order to exit out early.This has required some changes to some public parts of the
initializerpackage. If that's a problem, separate functions likeAnalyzeWithContextfunction could be added instead.User facing changes
Before: pressing CTRL-C
skaffold initdoes nothing, as the parent context is not connected to the analysis context.After: pressing CTRL-C during
skaffold initimmediately terminates the operation.