WIP, add/backport generic server-sent events support to Azure Core - #50081
WIP, add/backport generic server-sent events support to Azure Core#50081Xiaofei Cao (XiaofeiCao) wants to merge 4 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ff0a367c-664e-4de0-902b-ddaae2c86546
|
Azure Pipelines: Successfully started running 1 pipeline(s). 34 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ff0a367c-664e-4de0-902b-ddaae2c86546
Weidong Xu (weidongxu-microsoft)
left a comment
There was a problem hiding this comment.
The incremental parser needs a bounded pending-event size before this is safe to ship.
appendByte doubles lineBytes without a maximum, and completed data: lines are accumulated in data until a blank line. A server (or intermediary) can therefore send either one unterminated line or an unlimited sequence of data: lines without an empty-line dispatch and make the client retain the entire stream until heap exhaustion. This affects both the async and listener paths.
Please enforce a documented maximum line/event size and terminate the stream with a clear exception when it is exceeded. Add tests for both an oversized single line and many bounded lines without a terminating blank line.
Some thoughts(evidence collected by agent):
Spring's 256kb limit doesn't seem to fit our knowledgebase retrieval case. Since currently we don't have configuration for response body size(correct me if I'm wrong), I'd say we don't enforce this. |
|
Three minor follow-ups from the API/protocol pass:
These are non-blocking compared with the pending-event size concern. |
|
Agent-generated Java SSE interface design comparison and recommendations: https://gist.github.com/weidongxu-microsoft/f99f792a78f16cef8c9c1674c68e7d1b |
Summary aside, this is more or less the "alternative design" we've discussed. A closable stream pattern for sync. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: daa3657a-91d5-48fa-b7ae-6983091cab6a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: daa3657a-91d5-48fa-b7ae-6983091cab6a
Scope
Adds Azure Core support for single-response generic SSE consumption. It parses one established
Response<BinaryData>; it never reconnects, replays, or sendsLast-Event-Id.ServerSentEvent<T>,ServerSentEventListener<T>,ServerSentEventStreams, incremental SSE parsing, close-owning response handling, and optional typed terminal-event predicates.BinaryData, and Reactor.Contract
ServerSentEventStreamsis exported fromcom.azure.core.http; parser and response-owner types remain internal. Response overloads require aCloseableresponse and fail fast withIllegalArgumentExceptionotherwise. Non-204 responses require exactly onetext/event-streamcontent type; explicit non-UTF-8 charsets are rejected. Invalid or null-body responses are closed before failure.Existing overloads complete on EOF or HTTP 204. Predicate overloads deliver the matching typed terminal event, close the response, and complete; EOF before a match is an incomplete-stream error. All paths close the physical response on completion, failure, interruption, or Reactor cancellation.
Accept: text/event-streampreserves a live body only when itsqvalue is syntactically valid and greater than zero.Validation