Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ingress proxy unpacks assest and work slowly #3339

Closed
nurikk opened this issue Dec 3, 2021 · 23 comments
Closed

Ingress proxy unpacks assest and work slowly #3339

nurikk opened this issue Dec 3, 2021 · 23 comments

Comments

@nurikk
Copy link

nurikk commented Dec 3, 2021

Describe the issue you are experiencing

Hello from zigbee2mqtt team!

Recently many users started complaining that z2m frontend open slowly.

zigbee2mqtt/hassio-zigbee2mqtt#236
nurikk/zigbee2mqtt-frontend#1124

After some debugging i can see that when frontend is loaded through ingress proxy, it's loaded very slowly:
there are few symptoms:

  • Assets aren't gzip compressed
  • Missing caching headers
  • Sometimes response comes in form of headers from underlying backend as is, kind of http response parsing issue

Screenshot 2021-12-04 at 7 30 59 PM

Here're some screenshots

Screenshot 2021-12-03 at 10 31 18 AM

Screenshot 2021-12-03 at 4 51 00 PM

This how it looks if we request frontend directly, without ingress
First load (no cache)

Screenshot 2021-12-03 at 10 26 37 AM

Screenshot 2021-12-03 at 10 27 48 AM

After refresh
Screenshot 2021-12-03 at 10 25 09 AM

What is the used version of the Supervisor?

supervisor-2021.10.8

What type of installation are you running?

Home Assistant Supervised

Which operating system are you running on?

Debian

What is the version of your installed operating system?

Ubuntu 18.04.6 LTS

What version of Home Assistant Core is installed?

core-2021.11.5

Steps to reproduce the issue

  1. Install zigbee2mqtt addon
  2. Start it
  3. Open web ui

Anything in the Supervisor logs that might be useful for us?

no

Additional information

nurikodd.duckdns.org.har.zip

Attached HAR archive from chrome dev tools

@nurikk nurikk added the bug label Dec 3, 2021
@nurikk
Copy link
Author

nurikk commented Dec 3, 2021

Current workaround is to use websocat exported port for frontend and access directly on websocat port

Screenshot 2021-12-02 at 7 44 38 PM

@nurikk
Copy link
Author

nurikk commented Dec 4, 2021

Hey guys, may be you can help? @danielwelch @ciotlosm

@Bascht74
Copy link

right now the Z2M frontend looks like this every second time. If you press reload, everything is fine...
image

image

@Bascht74
Copy link

Bascht74 commented Jan 8, 2022

@frenck Hi, I am sorry that I "quoted" you directly in that issue, but I saw in the last HA shows that you use Z2M yourself. There is an issue with the frontend and ingress (which seems to be a part of HA supervisor). Maybe you face the problem yourself (you need to reload the frontend sometimes that it shows correctly)
@nurikk made this issue about it but no one seems to pick it up. Do you have any hint how to proceed?
I saw problems with ingress when HA started using it but now I am not sure if there is somebody who will cover the ingress part...

@frenck
Copy link
Member

frenck commented Jan 8, 2022

@Bascht74 i don't use z2m as an add-on.

@github-actions
Copy link

github-actions bot commented Mar 9, 2022

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 9, 2022
@Enzokot
Copy link

Enzokot commented Mar 9, 2022

Keep alive

@github-actions github-actions bot removed the stale label Mar 9, 2022
@github-actions
Copy link

github-actions bot commented May 8, 2022

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 8, 2022
@Bascht74
Copy link

Bascht74 commented May 8, 2022

Bump

@github-actions github-actions bot removed the stale label May 8, 2022
@github-actions
Copy link

github-actions bot commented Jul 7, 2022

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jul 7, 2022
@Enzokot
Copy link

Enzokot commented Jul 8, 2022

Keep alive

@github-actions github-actions bot removed the stale label Jul 8, 2022
@github-actions
Copy link

github-actions bot commented Sep 6, 2022

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Sep 6, 2022
@Enzokot
Copy link

Enzokot commented Sep 6, 2022

Keep alive

@github-actions github-actions bot removed the stale label Sep 6, 2022
@github-actions
Copy link

github-actions bot commented Oct 6, 2022

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 6, 2022
@Enzokot
Copy link

Enzokot commented Oct 6, 2022

Keep alive

@github-actions github-actions bot removed the stale label Oct 6, 2022
@github-actions
Copy link

github-actions bot commented Nov 5, 2022

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 5, 2022
@Bascht74
Copy link

Bascht74 commented Nov 5, 2022

bump.

@danielwelch @ciotlosm can you take a look?

@github-actions github-actions bot removed the stale label Nov 5, 2022
@Bascht74
Copy link

Bascht74 commented Dec 1, 2022

Anybody out here?

@Bascht74
Copy link

Bascht74 commented Dec 1, 2022

@balloob Hello Paul, normally HA issues are assigned by a bot, but here for the supervisor this doesn't seem to work.
I don't know what to do, just keeping this issue open.
Is there a better way or should i let the bot close the issue, as nobody seems to be able to take a look?
Thx for a small hint about that as I am clueless here...

@github-actions
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 31, 2022
@Bascht74
Copy link

Bascht74 commented Jan 1, 2023

Still no reaction and no assignment. Is that right?

@github-actions github-actions bot removed the stale label Jan 1, 2023
@mdegat01
Copy link
Contributor

Hey sorry for the delay on this one @Bascht74 . I'm digging into this now.

So first thing I noticed is that the cache-control header seems to be the same for both ingress and non-ingress connections to Z2M. And in my testing just now I do actually see Z2M hitting the cache when using ingress after the first refresh. I realize that its been a while since this bug was first reported, do you see that change as well? Or are you still seeing Z2M skipping the cache?

Dev tools for Z2M direct access on second refresh with cache allowed:
Screen Shot 2023-01-12 at 3 37 16 PM

Dev tools for Z2M ingress access on second refresh with cache allowed:
Screen Shot 2023-01-12 at 3 38 48 PM

Now for the other two parts. The response actually gets unpacked twice along the way to the client unfortunately. Since ingress everything from the HA frontend (including ingress requests) go to core first. Core then sees it is an ingress request and so passes it to supervisor. Supervisor then checks that it has a valid ingress session and if so passes it on to the addon. The process then runs in reverse for the response.

The request handling makes sense but the response handling is a bit illogical. Core obviously has to process the response since it is often asked to be the TLS endpoint by users when they add their SSL certs to its HTTP config. But supervisor never has to handle SSL and is basically just pass through. When I asked about this it seems there's a limitation in aiohttp around this. We let aiohttp handle encoding and apparently it always decodes response, there is no way to pass a response straight through without decoding it. I can research that more as that seems like the obvious improvement, perhaps something has changed.

Since supervisor currently has to decode the response it is currently leveraging that to decide whether to stream it in chunks or not:

# Simple request
if (
hdrs.CONTENT_LENGTH in result.headers
and int(result.headers.get(hdrs.CONTENT_LENGTH, 0)) < 4_194_000
):
# Return Response
body = await result.read()
return web.Response(
headers=headers,
status=result.status,
content_type=result.content_type,
body=body,
)
# Stream response
response = web.StreamResponse(status=result.status, headers=headers)
response.content_type = result.content_type
try:
await response.prepare(request)
async for data in result.content.iter_chunked(4096):
await response.write(data)
except (
aiohttp.ClientError,
aiohttp.ClientPayloadError,
ConnectionResetError,
) as err:
_LOGGER.error("Stream error with %s: %s", url, err)
return response

I'm suspicious that this is the source of your 0B responses but I'm having a hard time reproducing that. Do you still see that behavior?

The thing that seems like the top priority here is why isn't the response gzipped? I definitely see exactly what you're talking about there. My understanding is that this should be handled by aiohttp. The request headers include the accepted encodings so it should be encoding the output in one of the accepted formats. That doesn't seem to be happening which is confusing, will look into why.

@github-actions
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 11, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants