Skip to content

fix: settle closed request bodies and clear rejected-body timers - #8586

Open
DeepanshuPal wants to merge 2 commits into
netlify:mainfrom
DeepanshuPal:fix/request-body-stream-lifecycle
Open

DeepanshuPal wants to merge 2 commits into
netlify:mainfrom
DeepanshuPal:fix/request-body-stream-lifecycle

Conversation

@DeepanshuPal

Copy link
Copy Markdown

createStreamPromise leaves its timeout running when the body exceeds the size limit. It also does not handle a stream that closes before end, so that request waits for the timeout, or never settles when no finite timeout is set.

Clear the timeout on every terminal path and reject premature closure promptly. Mark a normally completed body as closed before resolving it, so the close event after end cannot change the result. Stream ownership and the body-size limit are unchanged.

Tests cover size rejection, early close with and without a timeout, normal chunk collection, stream errors, timeout, and later events after rejection. Two cases fail on unchanged code and all seven pass with the fix. The full unit suite passes (728 tests), along with build, typecheck, and lint/format checks. Integration and end-to-end suites were not run.

@DeepanshuPal
DeepanshuPal requested a review from a team as a code owner October 7, 2026 10:59
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 28be9df4-3fed-44b1-8958-e5ffca99ea03
📥 Commits

Reviewing files that changed from the base of the PR and between 2f8546e and 991e8c5.

📒 Files selected for processing (2)
  • src/utils/create-stream-promise.ts
  • tests/unit/utils/create-stream-promise.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Stream requests now reject promptly if a stream closes before completing.
    • Timeouts are cleared when streams end or fail, including when the body exceeds the size limit.

Walkthrough

createStreamPromise now clears its timeout when the body exceeds the byte limit, the stream errors, the stream closes before completion, or the stream ends. A premature close rejects with Stream closed before body completed. Tests cover these outcomes, later events after rejection, normal chunk concatenation, and timeout rejection for a stalled stream.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: amun-sihra

Merge Risk: ⚪ Minimal · up to 991e8

No actionable issue remains; the change is ready to merge after normal checks.

Architecture Summary

Architecture risk: 🔵 Low · up to 991e8

The change affects 2 systems.

Changed systems: src, tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — tests (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/utils/create-stream-promise.ts: A clearTimer helper cancels and nulls the timeout. The timeout callback now uses it after marking data unavailable.
  • observed — Modified behavior in src/utils/create-stream-promise.ts: When the accumulated body exceeds bytesLimit, the code now clears the timeout before rejecting with Stream body too big.
  • observed — Modified behavior in src/utils/create-stream-promise.ts: The error handler now clears the timeout after rejecting with the original stream error. A new close handler rejects with Stream closed before body completed and clears the timeout when data is still available; it marks data unavailable to prevent further harvesting.
  • observed — Modified behavior in src/utils/create-stream-promise.ts: The end handler now clears the timeout unconditionally, then marks data unavailable and resolves with the concatenated body when data is available. Previously, it cleared the timeout only if one existed and resolved directly with the concatenated body.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main changes: handling prematurely closed request bodies and clearing timers after rejection.
Description check ✅ Passed The description explains the stream issues, intended fixes, test coverage, and validation results. It is directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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.

1 participant