[http-client-python] Add automatic SSE reconnection - #11904
[http-client-python] Add automatic SSE reconnection#11904Libba Lawrence (l0lawrence) wants to merge 2 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6bf64cba-786a-41ee-8e45-8567e1cf8568
commit: |
|
All changed packages have been documented.
Show changes
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6bf64cba-786a-41ee-8e45-8567e1cf8568
|
You can try these changes here
|
| await aclose() | ||
| finally: | ||
| await self._response.close() | ||
| await asyncio.sleep((self._retry if self._retry is not None else 3000) / 1000) |
There was a problem hiding this comment.
if you have access to the transport here you can do await transport.sleep instead of importing asyncio directly. There is a way on core to do it for async
| events = self._decoder.aiter_events(self._response.iter_bytes()) | ||
| try: | ||
| async for event in events: | ||
| event_id = getattr(event, "id", None) |
There was a problem hiding this comment.
I think metadata-only SSE blocks are lost here. Per the SSE processing model, id updates the last event id buffer and retry updates the reconnection time even when the block has no data field and therefore dispatches no event. Because this state is only copied from yielded events, an EOF immediately after a metadata-only block reconnects with stale values
Structured SSE streams currently stop at unexpected EOF and require callers to manually resume with
last_event_idthrough an internal workaround. This adds automatic reconnection so generated clients follow the SSE processing model without requiring application-owned reconnect loops.The generated stream runtime now:
retry:value --- Do we want a 3 second default or would we prefer no time delay, just immediately try to reconnect?Last-Event-IDCloses #11761