-
Notifications
You must be signed in to change notification settings - Fork 4
fix: close test dir to avoid error.ProcessFdQuotaExceeded #82
Conversation
Signed-off-by: grapebaba <[email protected]>
Summary of ChangesHello @GrapeBaBa, 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 implements a crucial fix to prevent resource exhaustion during test runs. By ensuring that test directories are properly closed, it eliminates 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.
Pull Request Overview
This PR fixes a resource leak in generated static tests by ensuring directory handles are properly closed after use.
- Changes
test_dirfromconsttovarto allow deferred cleanup - Adds
defer test_dir.close()to ensure proper resource cleanup
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 correctly fixes a file descriptor leak in the generated test code by ensuring test_dir is closed. This is a great fix to prevent error.ProcessFdQuotaExceeded.
However, I've noticed that the test generator script, test/spec/write_static_tests.zig, has similar file descriptor leaks. The directories opened for iteration on lines 57, 75, and 93 are not being closed. I recommend fixing these as well to fully resolve the issue. A robust pattern for this would be:
var it = (try std.fs.cwd().openDir(path, .{ .iterate = true })).iterate();
defer it.dir.close();
while (try it.next()) |entry| {
// ...
}I've also left a small suggestion on the changed code to improve its clarity.
| \\ defer allocator.free(test_dir_name); | ||
| \\ | ||
| \\ const test_dir = std.fs.cwd().openDir(test_dir_name, .{{}}) catch return error.SkipZigTest; | ||
| \\ var test_dir = std.fs.cwd().openDir(test_dir_name, .{{}}) catch return error.SkipZigTest; |
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.
The test_dir variable doesn't need to be mutable here. The std.fs.Dir.close method takes its self parameter by value, so it can be called on a const variable. Using const makes the intent clearer that the variable is not meant to be modified after initialization.
\\ const test_dir = std.fs.cwd().openDir(test_dir_name, .{{}}) catch return error.SkipZigTest;
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.
no, close take mutable ptr
Fix #40