Skip to content

Fix /events AttributeError on browsers hitting the SSE endpoint - #69961

Open
dwoz wants to merge 1 commit into
saltstack:3007.xfrom
dwoz:dwoz/fix/69958-rest-cherrypy-events-iter-response
Open

Fix /events AttributeError on browsers hitting the SSE endpoint#69961
dwoz wants to merge 1 commit into
saltstack:3007.xfrom
dwoz:dwoz/fix/69958-rest-cherrypy-events-iter-response

Conversation

@dwoz

@dwoz dwoz commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #69958.

Root cause

A browser hitting /events sends Accept: text/html,*/*. html_override_tool raises cherrypy.InternalRedirect('/app') on that. The redirect propagates through cherrypy._cpwsgi.AppResponse.__init__; cherrypy 18.10.0's except BaseException: self.close() cleanup path then crashes with AttributeError: 'AppResponse' object has no attribute 'iter_response' because iter_response is only assigned after self.run() returns.

Fix

Skip the HTML override for any handler that opts 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 want text/event-stream, not text/html.

Test evidence

tests/pytests/unit/netapi/cherrypy/test_html_override.py:

  • test_html_override_skips_streaming_endpoints -- regression, fails without the fix (raises InternalRedirect), 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.

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

twangboy commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

We'll need to get that CI Deps fix into 3007.x or cherry-pick here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants