Skip to content

fix: prevent HTTP response body leaks in CLI API methods#336

Open
1Ckpwee wants to merge 1 commit into
plandex-ai:mainfrom
1Ckpwee:fix/http-response-body-leak
Open

fix: prevent HTTP response body leaks in CLI API methods#336
1Ckpwee wants to merge 1 commit into
plandex-ai:mainfrom
1Ckpwee:fix/http-response-body-leak

Conversation

@1Ckpwee
Copy link
Copy Markdown

@1Ckpwee 1Ckpwee commented Apr 8, 2026

Summary

Several API methods in app/cli/api/methods.go had HTTP response body leak issues:

  • GetCliTrialSession: defer resp.Body.Close() was placed after an early return on 404, so the body was never closed on that path
  • TellPlan: No defer resp.Body.Close() at all — body only closed in the non-streaming branch, leaked on error paths
  • BuildPlan: Same pattern as TellPlan
  • RespondMissingFile: No defer resp.Body.Close() anywhere
  • ConnectPlan: No defer resp.Body.Close() — body leaked on error paths

These leaks can cause resource exhaustion in long-running CLI sessions, especially when many API calls are made in succession.

Changes

  • Moved or added defer resp.Body.Close() immediately after the response is received in all affected methods
  • Removed redundant explicit resp.Body.Close() calls that are now covered by defer

Test plan

  • Verify existing tests still pass
  • Manual testing of plandex tell, plandex build, and plandex connect commands
  • Verify no regressions in streaming response handling

Add defer resp.Body.Close() immediately after receiving HTTP responses
in TellPlan, BuildPlan, RespondMissingFile, and ConnectPlan. Move the
defer in GetCliTrialSession before the early 404 return to prevent a
leak on that path. Remove redundant explicit resp.Body.Close() calls
that are now covered by defer.
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.

1 participant