Skip to content

fix(runtime): return proxied responses at headers instead of body EOF - #2159

Merged
jackwener merged 3 commits into
apache:mainfrom
Benjamin-eecs:fix/2126-streaming-proxied-fetch
Aug 4, 2026
Merged

fix(runtime): return proxied responses at headers instead of body EOF#2159
jackwener merged 3 commits into
apache:mainfrom
Benjamin-eecs:fix/2126-streaming-proxied-fetch

Conversation

@Benjamin-eecs

@Benjamin-eecs Benjamin-eecs commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

proxiedFetch used to await dispatcher.close(), and a graceful close waits for the active request. A streaming caller therefore did not receive the Response until body EOF.

What changed:

  • Return the original native Response as soon as headers arrive.
  • Start graceful dispatcher close without awaiting it. Undici keeps close pending until the active body reaches EOF, errors, or is cancelled.
  • Compose caller cancellation and the time-to-headers timeout with AbortSignal.any, so abort after headers still reaches the original streamed body without a manual listener.
  • Preserve the complete Fetch contract, including Response identity, URL metadata, redirect metadata, and immutable response headers.
  • Timeout and request-error paths still destroy the dispatcher. timeoutMs: 0 remains supported.

No shared proxy pool and no global proxy setting changes.

Closes #2126

Verification

  • @maka/runtime full suite: 3140 tests, 3131 passed, 0 failed, 9 skipped.
  • Regression tests use a real local proxy and prove the Response arrives before the held body tail, the first chunk is readable immediately, EOF and cancel release resources, caller abort after headers terminates the original body, native response headers stay immutable, and both timeout paths remain bounded.
  • npm run build:test passed.
  • Biome and git diff --check passed.
  • Desktop and e2e suites were not run; the change is confined to @maka/runtime.

@Benjamin-eecs
Benjamin-eecs marked this pull request as ready for review August 4, 2026 13:51
Copilot AI lite review requested due to automatic review settings August 4, 2026 13:51

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

proxiedFetch awaited dispatcher.close() in a finally block before the
outer promise could resolve, so a streaming response through a proxy was
withheld until its body reached EOF. Return the Response as soon as
headers arrive and tie cleanup to the returned body's lifecycle instead:
the re-wrapped body reports when it reaches EOF, errors, or is
cancelled; the caller abort listener detaches at that point, and the
graceful dispatcher close is no longer awaited. Timeout and error paths
stay destructive and bounded, and the timeout keeps bounding
time-to-headers only.

Closes apache#2126
@Benjamin-eecs
Benjamin-eecs force-pushed the fix/2126-streaming-proxied-fetch branch from a6c18f7 to 608eac5 Compare August 4, 2026 14:04
@jackwener
jackwener merged commit e19c6c3 into apache:main Aug 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proxiedFetch waits for proxied response EOF before returning the Response

3 participants