Skip to content

Destroy upstream body when pipe fails - #55

Merged
KevinPayravi merged 2 commits into
mainfrom
upgrade-hotfix
Nov 2, 2026
Merged

KevinPayravi merged 2 commits into
mainfrom
upgrade-hotfix

Conversation

@KevinPayravi

@KevinPayravi KevinPayravi commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

With the upgrade to Node 24 (#53), pipeline() rejects immediately when the response is already destroyed and the fetched body is left open. When the fetch timeout fires 5 seconds later, the orphaned body emits a TimeoutError and the worker crashes.

With this PR, the source in now destoyed on failure and the body is cancelled.

CodeRabbit Summary

Summary

  • ResponseHelper.pipe now attaches a no-op error listener to the converted upstream stream before calling pipeline(). This absorbs upstream errors that occur before pipeline() attaches. The existing failure handler still destroys the source, logs the error, and ends the response when needed.
  • Added tests for upstream body cancellation and for preventing an uncaught exception when the body errors before piping to a destroyed response.

The supplied evidence does not establish whether a manual pipeline trigger or ECS redeployment is required. The commit changes no environment variables, AWS Secrets Manager keys, database migrations, shared infrastructure configuration, or public API response shapes or endpoints. No security changes are indicated. Test execution results are not provided.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

CodeRabbit ASCII loading animation

Currently processing new changes in this PR. This may take a few minutes, please wait...

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: c1453c93-6744-455b-9129-c2d8514cdc0d
Commits

Reviewing files that changed from the base of the PR and between ef18539 and e2e1f45.

Files selected for processing: 2
  • src/ResponseHelper.ts
  • test/unit/ResponseHelper.test.ts
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: dd4907a8-c42d-4613-a87c-4cd0e8dcc4b6
Commits

Reviewing files that changed from the base of the PR and between 31ba4d1 and ef18539.

Files selected for processing: 2
  • src/ResponseHelper.ts
  • test/unit/ResponseHelper.test.ts

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Walkthrough

pipe now retains the converted readable stream and destroys it when pipeline throws. A test checks that the upstream stream is canceled once when piping to an already-destroyed response.

Changes

Pipe failure cleanup

Layer / File(s) Summary
Destroy the source stream on pipeline failure
src/ResponseHelper.ts, test/unit/ResponseHelper.test.ts
pipe destroys the converted readable stream if pipeline throws. The test verifies that the upstream stream’s cancel method is called once when the response is already destroyed.

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

Possibly related PRs

  • dpla/thumbnail-api#21: Introduced the pipeline(Readable.fromWeb(body), expressResponse) call and catch block that this change updates.
  • dpla/thumbnail-api#53: Updated the project to Node 24; this PR addresses pipeline rejection behavior under that runtime.
Merge Risk: Moderate · previous review ef185

The change fixes the main case of leaving the fetched body open when the response is already destroyed. A remaining edge case, where the fetched body has already errored, can still emit an unhandled error and crash the worker. Attach a source error listener before piping before merging.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Destroy upstream body when pipe fails" matches the main change. The summary says ResponseHelper.pipe now keeps the Readable.fromWeb(body) stream as source and destroys it when pipeline thro…
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.
Full details: Title check

Explanation

The title "Destroy upstream body when pipe fails" matches the main change. The summary says ResponseHelper.pipe now keeps the Readable.fromWeb(body) stream as source and destroys it when pipeline throws. The PR objectives state the same intent: destroy the source and cancel the fetched body when pipeline() fails. The title is specific, short, and does not use vague terms. The test addition covers the same behavior, and the title does not need to mention it.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread src/ResponseHelper.ts Resolved
@KevinPayravi
KevinPayravi merged commit 987f249 into main Nov 2, 2026
6 of 7 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.

1 participant