fix: close file descriptor after writing temp settings file#2272
Open
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
Open
fix: close file descriptor after writing temp settings file#2272wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
Conversation
`tempfile.mkstemp()` returns an open file descriptor that was never closed after `os.write()`. In a long-running server process, each call to `apply_repo_settings()` leaks one fd, eventually exhausting the system file descriptor limit. The `finally` block removes the file but does not close the descriptor. Made-with: Cursor
Contributor
Review Summary by QodoClose file descriptor after writing temp settings file
WalkthroughsDescription• Close file descriptor after writing temp settings file • Prevents file descriptor leak in long-running server processes • Fixes exhaustion of system fd limit on repeated settings applications Diagramflowchart LR
A["tempfile.mkstemp returns open fd"] --> B["os.write writes to fd"]
B --> C["os.close closes fd"]
C --> D["finally block removes temp file"]
D --> E["No fd leak"]
File Changes1. pr_agent/git_providers/utils.py
|
Contributor
Code Review by Qodo
1. fd not closed on error
|
Comment on lines
37
to
+39
| fd, repo_settings_file = tempfile.mkstemp(suffix='.toml') | ||
| os.write(fd, repo_settings) | ||
| os.close(fd) |
Contributor
There was a problem hiding this comment.
1. fd not closed on error 📘 Rule violation ⛯ Reliability
The new os.close(fd) is not protected by a finally, so an exception from `os.write(fd, repo_settings)` can still leak the file descriptor. This does not fully meet the robust error-handling requirement for cleanup on failure paths.
Agent Prompt
## Issue description
`os.close(fd)` is executed only if `os.write(fd, repo_settings)` succeeds; if `os.write` raises, the file descriptor can still leak.
## Issue Context
This code uses `tempfile.mkstemp()` which returns a raw OS file descriptor that must be closed on all paths (success and exception).
## Fix Focus Areas
- pr_agent/git_providers/utils.py[37-39]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
pr_agent/git_providers/utils.py: Added os.close(fd) after os.write(fd, repo_settings)
Test plan