Skip to content

Work around ingress glitch with 304 responses#63355

Merged
balloob merged 2 commits into
home-assistant:devfrom
masto:no-chunk-304
Jan 4, 2022
Merged

Work around ingress glitch with 304 responses#63355
balloob merged 2 commits into
home-assistant:devfrom
masto:no-chunk-304

Conversation

@masto
Copy link
Copy Markdown
Contributor

@masto masto commented Jan 4, 2022

Proposed change

This is a small workaround for an issue I noticed when using the ESPHome add-on (though it is not specific to that add-on). The ingress proxy rewrites "304 Not Modified" responses into chunked transfer-encoding, which triggers a series of weird browser behaviors. I don't know exactly why, but I wrote up the observed symptoms and in detail in esphome/issues#2908. This one-line change makes the problem go away.

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

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 Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @home-assistant/supervisor, mind taking a look at this pull request as it has been labeled with an integration (hassio) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Jan 4, 2022
@elupus
Copy link
Copy Markdown
Contributor

elupus commented Jan 4, 2022

It seems a zero length chunk is indicative of end of stream. So it's expected to close the connection after this has been received. The client should re-open a new connection on the next request. I wonder what is getting confused by this closed connection.

@elupus
Copy link
Copy Markdown
Contributor

elupus commented Jan 4, 2022

I think this is correct, we should however also add 204 "no content" responses. Both 304 and 204 are expected empty responses, that will "break" chunked encoding.

@masto
Copy link
Copy Markdown
Contributor Author

masto commented Jan 4, 2022

As you say, closing the connection may well be correct behavior. (I got so caught up in the weeds I probably lost sight of that). Why it breaks Safari is a mystery -- perhaps there's some tiny out-of-spec implementation detail that can be found with more detailed inspection. All I can say is that Safari does something weird under these conditions.

Comment thread homeassistant/components/hassio/ingress.py Outdated
@frenck frenck added this to the 2021.12.8 milestone Jan 4, 2022
@frenck
Copy link
Copy Markdown
Member

frenck commented Jan 4, 2022

Tagged it for the milestone (although... it does affect Ingress, so we should be careful)

@balloob balloob merged commit 32933b2 into home-assistant:dev Jan 4, 2022
balloob added a commit that referenced this pull request Jan 4, 2022
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
@balloob balloob mentioned this pull request Jan 4, 2022
hdrs.CONTENT_LENGTH in result.headers
and int(result.headers.get(hdrs.CONTENT_LENGTH, 0)) < 4194000
):
) or result.status in (204, 304):
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.

This should use (HTTPStatus.NO_CONTENT, HTTPStatus.NOT_MODIFIED) and should have a test that proves that these 2 statuses return Response and not StreamResponse

@github-actions github-actions Bot locked and limited conversation to collaborators Jan 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix cherry-picked cla-signed core integration: hassio small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"An error occurred saving" message in Safari due to bad ingress proxying for 304 responses

6 participants