Repository navigation
Destroy upstream body when pipe fails - #55
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait...
|
| 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: 
4
-
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.
-

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 aTimeoutErrorand the worker crashes.With this PR, the source in now destoyed on failure and the body is cancelled.
CodeRabbit Summary
Summary
ResponseHelper.pipenow attaches a no-operrorlistener to the converted upstream stream before callingpipeline(). This absorbs upstream errors that occur beforepipeline()attaches. The existing failure handler still destroys the source, logs the error, and ends the response when needed.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.