Skip to content

fix(core): explicitly close httpc socket to prevent file descriptor leak in PAUSE loop#1466

Open
varun-ai69 wants to merge 3 commits into
krkn-chaos:mainfrom
varun-ai69:fix/1463-close-httpc-socket-leak
Open

fix(core): explicitly close httpc socket to prevent file descriptor leak in PAUSE loop#1466
varun-ai69 wants to merge 3 commits into
krkn-chaos:mainfrom
varun-ai69:fix/1463-close-httpc-socket-leak

Conversation

@varun-ai69

@varun-ai69 varun-ai69 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Type of change

  • Refactor
  • New feature
  • Bug fix
  • Optimization

Description

When Kraken is running in PAUSE state (e.g., signal_state: PAUSE with a short polling interval), the server.get_status() method is called continuously to poll the server. Previously, it opened a new HTTPConnection on every check but never explicitly closed it.
This resulted in a critical TCP socket resource leak inside the OS where the garbage collector could not keep up, eventually causing the system to crash with an OSError: [Errno 24] Too many open files (or [WinError 10048] on Windows).
This PR fixes the issue by explicitly adding httpc.close() before the function returns in server.get_status(), safely destroying the socket and keeping the file descriptor count flat during long wait loops.

Related Tickets & Documents

If no related issue, please create one and start the converasation on wants of

Documentation

  • Is documentation needed for this update?

Related Documentation PR (if applicable)

  • N/A

Checklist before requesting a review

  • Ensure the changes and proposed solution have been discussed in the relevant issue and have received acknowledgment from the community or maintainers. See contributing guidelines
    See testing your changes and run on any Kubernetes or OpenShift cluster to validate your changes
  • I have performed a self-review of my code by running krkn and specific scenario
  • If it is a core feature, I have added thorough unit tests with above 80% coverage

REQUIRED:
Description of combination of tests performed and output of run

python -m coverage run -a -m unittest discover -s tests -v
`----------------------------------------------------------------------
Ran 1093 tests in 19.739s

FAILED (errors=3)`

…eak in PAUSE loop

Signed-off-by: varun-ai69 <kushwahavarun86@gmail.com>

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Risk Analyzer Agent🛡️

Risk Analysis 🛡️ · Low Risk

✅ Approved — Low-Risk Change

Details

Purely additive one-line resource cleanup: adds httpc.close() after response.read() in server.get_status(), on the successful return path. Fixes the FD leak in the PAUSE polling loop described in the PR body / issue #1463. HTTPConnection.close() on a fully-read response is a standard-library-safe call. Diff is confined to server.py; no opted-out paths, schemas, auth, infra, or observable behavior change.

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep Code Review Agent🐛

Review completed with 1 suggestion.

Fix in Cosmos

Comment thread server.py Outdated
… on network failure

Signed-off-by: varun-ai69 <kushwahavarun86@gmail.com>
@github-actions github-actions Bot added size/s and removed size/xs labels Jul 10, 2026
… test to check connection closes even when request() raises

Signed-off-by: varun-ai69 <kushwahavarun86@gmail.com>
@varun-ai69

Copy link
Copy Markdown
Contributor Author

hey @paigerube14 @ddjain @tsebastiani @chaitanyaenr can you please review the pr whenever you are freee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: TCP Socket Resource Leak in server.get_status() Due to Unclosed HTTPConnection

1 participant