Skip to content

[azure-core] Fix partial InputStream response buffering - #50837

Merged
Alan Zimmer (alzimmermsft) merged 4 commits into
Azure:mainfrom
XiaofeiCao:xiaofeicao-fix-streaming-response-buffering
Oct 26, 2026
Merged

Alan Zimmer (alzimmermsft) merged 4 commits into
Azure:mainfrom
XiaofeiCao:xiaofeicao-fix-streaming-response-buffering

Conversation

@XiaofeiCao

Copy link
Copy Markdown
Member

Description

Bug

FluxUtil.toFluxByteBuffer continues reading until its configured chunk is full or EOF is reached. A small flushed response chunk is therefore withheld while the next read blocks, which can stall long-lived streams such as SSE.

The bug affects JDK sync and OkHttp sync/async response streaming. JDK async, Netty, and Vert.x do not have this issue.

Azure Search #50648 consumes streaming BinaryData through body.toFluxByteBuffer() for async APIs and body.toStream() for sync APIs.

JDK sync converts its response InputStream through FluxUtil.toFluxByteBuffer, while OkHttp sync/async use FluxUtil.toFluxByteBuffer(responseBody.byteStream(), 8192). JDK async uses the JDK publisher directly, Netty uses Reactor Netty ByteBufFlux, and Vert.x uses Buffer callbacks.

Fix

Perform one demand-driven blocking read, coalesce only bytes reported as immediately available, and emit the partial buffer without waiting for the configured chunk to fill.

This fixes JDK sync and OkHttp sync/async while preserving the existing behavior of JDK async, Netty, and Vert.x.

Validation

Added unit and shared HTTP-client coverage verifying flushed partial responses arrive before EOF. Azure Core tests passed (11,891 tests, 3 skipped), including targeted JDK and OkHttp sync/async regressions. Checkstyle and SpotBugs also passed.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Emit partial response data once no additional bytes are immediately available, while opportunistically coalescing buffered bytes up to the configured chunk size.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7eaead83-8f9e-4c68-9958-ad8e66668356
Verify JDK and OkHttp clients deliver a flushed SSE frame before the response reaches EOF.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7eaead83-8f9e-4c68-9958-ad8e66668356
@github-actions github-actions Bot added the Azure.Core azure-core label Oct 16, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@XiaofeiCao Xiaofei Cao (XiaofeiCao) changed the title Fix partial InputStream response buffering [azure-core] Fix partial InputStream response buffering Oct 16, 2026
@XiaofeiCao
Xiaofei Cao (XiaofeiCao) marked this pull request as ready for review October 16, 2026 09:34
Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The localized buffering correction has targeted unit and HTTP regression coverage, with no identified blocking defects.

0 open findings

What changed in this PR

Fixes Azure Core’s InputStream response buffering so flushed partial data can reach streaming consumers without waiting for a full chunk or EOF.

Changes:

  • Limits additional reads to immediately available bytes.
  • Adds unit and shared HTTP regression coverage for partial responses.
  • Documents the streaming fix in the changelog.
File Description
sdk/​core/​azure-core/​src/​test/​java/​com/​azure/​core/​validation/​http/​HttpClientTestsServer.java Adds a flushed response with delayed completion.
sdk/​core/​azure-core/​src/​test/​java/​com/​azure/​core/​validation/​http/​HttpClientTests.java Verifies early delivery through sync and async clients.
sdk/​core/​azure-core/​src/​test/​java/​com/​azure/​core/​util/​FluxUtilTest.java Tests partial reads before stream completion.
sdk/​core/​azure-core/​src/​main/​java/​com/​azure/​core/​util/​FluxUtil.java Emits partial buffers without waiting to fill them.
sdk/​core/​azure-core/​CHANGELOG.md Records the streaming behavior fix.

🧠 Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7eaead83-8f9e-4c68-9958-ad8e66668356
@alzimmermsft
Alan Zimmer (alzimmermsft) merged commit 57a0f12 into Azure:main Oct 26, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core azure-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants