Skip to content

Commit 27b15b6

Browse files
frankbriaTest User
andauthored
fix(pr_v2): close httpx client in all 5 remaining PR endpoints (#582)
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 Co-authored-by: Test User <test@example.com>
1 parent 28a4f91 commit 27b15b6

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

codeframe/ui/routers/pr_v2.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ async def list_pull_requests(
259259
Returns:
260260
List of pull requests
261261
"""
262+
client = _get_github_client()
262263
try:
263-
client = _get_github_client()
264264
prs = await client.list_pull_requests(state=state)
265265

266266
return PRListResponse(
@@ -281,6 +281,8 @@ async def list_pull_requests(
281281
status_code=500,
282282
detail=api_error("Failed to list PRs", ErrorCodes.EXECUTION_FAILED, str(e)),
283283
)
284+
finally:
285+
await client.close()
284286

285287

286288
@router.get("/{pr_number}", response_model=PRResponse)
@@ -299,8 +301,8 @@ async def get_pull_request(
299301
Returns:
300302
PR details
301303
"""
304+
client = _get_github_client()
302305
try:
303-
client = _get_github_client()
304306
pr = await client.get_pull_request(pr_number)
305307

306308
return _pr_to_response(pr)
@@ -323,6 +325,8 @@ async def get_pull_request(
323325
status_code=500,
324326
detail=api_error("Failed to get PR", ErrorCodes.EXECUTION_FAILED, str(e)),
325327
)
328+
finally:
329+
await client.close()
326330

327331

328332
@router.post("", response_model=PRResponse, status_code=201)
@@ -342,8 +346,8 @@ async def create_pull_request(
342346
Returns:
343347
Created PR details
344348
"""
349+
client = _get_github_client()
345350
try:
346-
client = _get_github_client()
347351
pr = await client.create_pull_request(
348352
branch=body.branch,
349353
title=body.title,
@@ -366,6 +370,8 @@ async def create_pull_request(
366370
status_code=500,
367371
detail=api_error("Failed to create PR", ErrorCodes.EXECUTION_FAILED, str(e)),
368372
)
373+
finally:
374+
await client.close()
369375

370376

371377
@router.post("/{pr_number}/merge", response_model=MergeResponse)
@@ -389,8 +395,8 @@ async def merge_pull_request(
389395
"""
390396
method = body.method if body else "squash"
391397

398+
client = _get_github_client()
392399
try:
393-
client = _get_github_client()
394400
result = await client.merge_pull_request(pr_number, method=method)
395401

396402
return MergeResponse(
@@ -422,6 +428,8 @@ async def merge_pull_request(
422428
status_code=500,
423429
detail=api_error("Failed to merge PR", ErrorCodes.EXECUTION_FAILED, str(e)),
424430
)
431+
finally:
432+
await client.close()
425433

426434

427435
@router.post("/{pr_number}/close")
@@ -440,8 +448,8 @@ async def close_pull_request(
440448
Returns:
441449
Close confirmation
442450
"""
451+
client = _get_github_client()
443452
try:
444-
client = _get_github_client()
445453
closed = await client.close_pull_request(pr_number)
446454

447455
return {
@@ -467,3 +475,5 @@ async def close_pull_request(
467475
status_code=500,
468476
detail=api_error("Failed to close PR", ErrorCodes.EXECUTION_FAILED, str(e)),
469477
)
478+
finally:
479+
await client.close()

0 commit comments

Comments
 (0)