Fix /events AttributeError on browsers hitting the SSE endpoint - #69961
Open
dwoz wants to merge 1 commit into
Open
Fix /events AttributeError on browsers hitting the SSE endpoint#69961dwoz wants to merge 1 commit into
dwoz wants to merge 1 commit into
Conversation
Refs: saltstack#69958 A browser (or any Accept: text/html client) hitting /events triggered html_override_tool to raise cherrypy.InternalRedirect. That redirect propagates through cherrypy._cpwsgi.AppResponse.__init__ where the `except BaseException: self.close()` cleanup path in cherrypy 18.10.0 crashes with AttributeError: 'AppResponse' object has no attribute 'iter_response' (iter_response is only assigned after self.run() returns). Skip the html override for any handler that has opted into response.stream (the SSE /events endpoint and the /ws websocket endpoint). Diverting a streaming handler to the HTML app is wrong regardless of the cherrypy bug -- SSE clients ask for text/event-stream, not text/html -- so this narrows the tool's blast radius as well.
twangboy
approved these changes
Aug 5, 2026
Contributor
|
We'll need to get that CI Deps fix into 3007.x or cherry-pick here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #69958.
Root cause
A browser hitting
/eventssendsAccept: text/html,*/*.html_override_toolraisescherrypy.InternalRedirect('/app')on that. The redirect propagates throughcherrypy._cpwsgi.AppResponse.__init__; cherrypy 18.10.0'sexcept BaseException: self.close()cleanup path then crashes withAttributeError: 'AppResponse' object has no attribute 'iter_response'becauseiter_responseis only assigned afterself.run()returns.Fix
Skip the HTML override for any handler that opts into
response.stream(the SSE/eventsendpoint and the/wswebsocket endpoint). Diverting a streaming handler to the HTML app is wrong regardless of the cherrypy bug -- SSE clients wanttext/event-stream, nottext/html.Test evidence
tests/pytests/unit/netapi/cherrypy/test_html_override.py:test_html_override_skips_streaming_endpoints-- regression, fails without the fix (raisesInternalRedirect), passes with it.test_html_override_still_redirects_non_streaming_html_request-- sanity check that non-streaming HTML requests still divert to/app.All 13 existing
tests/pytests/unit/netapi/cherrypy/tests pass.