Skip to content

Conversation

agners
Copy link
Member

@agners agners commented Jul 1, 2025

Proposed change

An empty data chunk signifies EOF. Stop streaming the response in that case.

See https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/streams.py#L471-L474.

Related to: home-assistant/core#147899

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to cli pull request:
  • Link to client library pull request:

Checklist

  • 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
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming response handling to prevent sending empty data chunks to users.

@agners agners requested a review from bdraco July 1, 2025 19:24
@agners agners added the bugfix A bug fix label Jul 1, 2025
Copy link
Contributor

coderabbitai bot commented Jul 1, 2025

📝 Walkthrough

Walkthrough

The update modifies the streaming logic in the _handle_request method within the ingress API. It now checks for empty data chunks during asynchronous iteration over the response content and stops streaming when an empty chunk is encountered, altering how data is forwarded to the client.

Changes

File(s) Change Summary
supervisor/api/ingress.py Added a check to break the streaming loop if an empty data chunk is received.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant IngressAPI
    participant ProxiedService

    Client->>IngressAPI: Send request
    IngressAPI->>ProxiedService: Forward request
    ProxiedService-->>IngressAPI: Stream response chunks
    loop For each chunk
        IngressAPI->>IngressAPI: Check if chunk is empty
        alt Chunk is not empty
            IngressAPI-->>Client: Write chunk
        else Chunk is empty
            IngressAPI->>IngressAPI: Break loop, stop streaming
        end
    end
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (3.3.7)
supervisor/api/ingress.py
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 38750d7 and f67f67c.

📒 Files selected for processing (1)
  • supervisor/api/ingress.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Run tests Python 3.13.5
  • GitHub Check: Build armv7 supervisor
  • GitHub Check: Build armhf supervisor
  • GitHub Check: Build aarch64 supervisor

@frenck frenck requested a review from Copilot July 1, 2025 20:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Stop streaming the response on receiving an empty data chunk (EOF) to prevent sending unnecessary empty writes.

  • Add an EOF check inside the streaming loop.
  • Break out of the loop when no data is returned.
Comments suppressed due to low confidence (2)

supervisor/api/ingress.py:283

  • Consider adding a test (unit or integration) to cover the case where iter_chunks() yields an empty data chunk, verifying that the loop breaks as expected and the response completes cleanly.
                    if not data:

supervisor/api/ingress.py:283

  • [nitpick] Add an inline comment explaining that an empty data chunk signifies EOF per aiohttp semantics, and that the break ensures the stream terminates properly.
                    if not data:

@agners agners marked this pull request as draft July 2, 2025 11:22
@agners
Copy link
Member Author

agners commented Jul 2, 2025

This needs more discussion, see home-assistant/core#147899 (comment).

Copy link
Contributor

github-actions bot commented Aug 1, 2025

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Aug 1, 2025
@agners
Copy link
Member Author

agners commented Aug 7, 2025

Core code adopted the approach avoid reading empty content by checking the request using must_be_empty_body().

No changes needed on Supervisor side.

A fix which avoids the endless loop in aiohttp got proposed with aio-libs/aiohttp#11397.

@agners agners closed this Aug 7, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2025
@agners agners deleted the stop-streaming-response-if-stream-is-eof branch September 15, 2025 07:52
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.

1 participant