Fix Supervisor connection leak when leaving an app's log page by jeffothy · Pull Request #183772 · home-assistant/core · GitHub
Skip to content

Fix Supervisor connection leak when leaving an app's log page - #183772

Merged
agners merged 2 commits into
home-assistant:devfrom
jeffothy:hassio-log-follow-connection-leak
Oct 1, 2026
Merged

agners merged 2 commits into
home-assistant:devfrom
jeffothy:hassio-log-follow-connection-leak

Conversation

@jeffothy

@jeffothy jeffothy commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Proposed change

Leaving an app's log page, or reloading it, makes the frontend abort its logs/follow stream. The handler in HassIOView gets cancelled, but the response from the Supervisor never gets released, so its connection stays in use until Core restarts.

Most of the time that's fine, since aiohttp releases the connection by itself once the body has been fully read. A follow stream never finishes though, and NO_TIMEOUT gives it no total timeout. So each visit to a log page leaks a connection, and after 100 of them every Supervisor call times out: the apps page won't load and ingress panels just hang.

The fix opens the request with async with, so the response is released when the handler exits, including when it's cancelled. The test helper's mock response now releases on exit too, like aiohttp's.

I added a test that cancels the stream partway through and checks the response gets released. It fails on dev without this change.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI balanced review requested due to automatic review settings September 30, 2026 15:02
@home-assistant

Copy link
Copy Markdown
Contributor

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The focused fix correctly handles cancellation and includes appropriate regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes leaked Supervisor connections when log streaming is cancelled.

Changes:

  • Releases Supervisor responses in all completion paths.
  • Adds cancellation regression coverage.
File Description
homeassistant/​components/​hassio/​http.py Releases upstream responses in finally.
tests/​components/​hassio/​test_http.py Verifies release after stream cancellation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@agners agners left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch, thanks for the PR! We can make it a bit prettier (and technically slightly better) by using async context manager.

Comment thread homeassistant/components/hassio/http.py Outdated
@home-assistant
home-assistant Bot marked this pull request as draft October 1, 2026 10:49
@home-assistant

home-assistant Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Copilot AI balanced review requested due to automatic review settings October 1, 2026 14:33
@jeffothy
jeffothy marked this pull request as ready for review October 1, 2026 14:34
@home-assistant
home-assistant Bot requested a review from agners October 1, 2026 14:34

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The focused fix correctly manages response lifetime and includes suitable regression coverage.

Review effort: Balanced
Findings: None

@agners agners left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, LGTM, thanks!

@agners
agners merged commit d413f4c into home-assistant:dev Oct 1, 2026
54 checks passed
@agners agners added this to the 2026.10.0 milestone Oct 1, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants