Skip to content

fix(pr_v2): close httpx client in all 5 remaining PR endpoints#582

Merged
frankbria merged 1 commit intomainfrom
fix/pr-v2-httpx-client-leak
Apr 14, 2026
Merged

fix(pr_v2): close httpx client in all 5 remaining PR endpoints#582
frankbria merged 1 commit intomainfrom
fix/pr-v2-httpx-client-leak

Conversation

@frankbria
Copy link
Copy Markdown
Owner

@frankbria frankbria commented Apr 14, 2026

Summary

  • Applies the try/finally: await client.close() pattern (already established in get_pr_status) to the five endpoints that were leaking httpx.AsyncClient connections
  • Affected endpoints: list_pull_requests, get_pull_request, create_pull_request, merge_pull_request, close_pull_request
  • No logic changes — only client lifecycle management

Test plan

  • 155 existing UI tests pass (uv run pytest tests/ui/)
  • ruff check clean
  • Pattern matches get_pr_status exactly

Closes #581

Summary by CodeRabbit

  • Refactor
    • Improved handling of pull request operations to ensure consistent resource cleanup across all endpoints.

Apply the try/finally client lifecycle pattern already established in
get_pr_status to list_pull_requests, get_pull_request, create_pull_request,
merge_pull_request, and close_pull_request. Prevents fd/socket leaks under
load by guaranteeing await client.close() on all code paths.

Closes #581
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 76619dd0-8e4f-4820-ac6d-3ef12d9b60d7

📥 Commits

Reviewing files that changed from the base of the PR and between 28a4f91 and e206153.

📒 Files selected for processing (1)
  • codeframe/ui/routers/pr_v2.py

Walkthrough

The PR applies a consistent client cleanup pattern across 5 PR endpoints in the router. Each endpoint now initializes the GitHub AsyncClient outside the try block and guarantees closure via a finally clause, preventing file descriptor leaks under load.

Changes

Cohort / File(s) Summary
PR Router Client Cleanup
codeframe/ui/routers/pr_v2.py
Applied try/finally: await client.close() pattern to 5 endpoints (list_pull_requests, get_pull_request, create_pull_request, merge_pull_request, close_pull_request) to ensure httpx AsyncClient connections are properly closed on all code paths, including error scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Five endpoints freed from leaky fate,
Finally blocks ensure they don't stay late,
Sockets close before they pile too high,
No more file descriptors reaching for the sky!
The rabbit rejoices, connections are tight! 🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: applying client closure to five PR endpoints.
Linked Issues check ✅ Passed The PR applies the try/finally pattern to all five specified endpoints (list_pull_requests, get_pull_request, create_pull_request, merge_pull_request, close_pull_request) as required by issue #581.
Out of Scope Changes check ✅ Passed All changes are limited to adding client initialization and cleanup patterns in the five specified endpoints; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #581

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pr-v2-httpx-client-leak

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link
Copy Markdown

claude bot commented Apr 14, 2026

Review

LGTM — clean, focused fix.

The pattern is applied consistently and correctly across all five endpoints. Moving _get_github_client() before the try block is the right call: if that call raises HTTPException (missing config), the finally branch never runs, so there's no dangling reference. Closing in finally ensures cleanup on both happy and error paths.

One minor note

If client.close() itself raises, it will mask the original exception — a known Python try/finally limitation. For this codebase it's almost certainly a non-issue (HTTP client teardown is rarely lossy), but worth knowing if you ever need to debug a swallowed error. A defensive guard would look like:

finally:
    try:
        await client.close()
    except Exception:
        logger.debug("Error closing GitHub client", exc_info=True)

That said, this is the same pattern as get_pr_status and doesn't need to change here — just flagging it as a follow-up if it ever becomes a pain point.

Checklist

  • Pattern matches get_pr_status exactly (per PR description)
  • All five leaking endpoints addressed
  • No logic changes
  • except HTTPException: raise is present in all endpoints to prevent re-wrapping
  • ruff check clean per test plan

@frankbria frankbria merged commit 27b15b6 into main Apr 14, 2026
11 checks passed
@frankbria frankbria deleted the fix/pr-v2-httpx-client-leak branch April 14, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(pr_v2): httpx client fd leak in 5 remaining PR endpoints

1 participant