fix(package): avoid double-response on async upload cleanup errors#140
Open
codxbrexx wants to merge 1 commit intometacall:masterfrom
Open
fix(package): avoid double-response on async upload cleanup errors#140codxbrexx wants to merge 1 commit intometacall:masterfrom
codxbrexx wants to merge 1 commit intometacall:masterfrom
Conversation
Prevent packageUpload from forwarding late async cleanup errors after the upload response has already been sent. This keeps the server from trying to handle the same request twice and adds focused controller tests for the guarded behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a package upload error-handling bug in
src/controller/package.ts.During package extraction and cleanup, temporary blob deletion can fail asynchronously. Before this fix, those late cleanup errors still flowed into
next(error)even after the upload had already returned201 Created. That creates a second Express error path after the response is already committed, which can make the server try to send another response for the same request.The fix adds a small response-settlement guard so asynchronous cleanup failures are only forwarded while the request is still active. If the response has already been sent, the error is safely ignored and logged instead of attempting a second response.
Problem statement
The package upload route performs asynchronous cleanup after the uploaded zip has been written and extracted. One of those cleanup steps deletes the temporary blob from disk.
If that cleanup fails after the success response has already been sent, the previous code still called the shared error handler. In Express, that means trying to enter the error middleware after headers are already sent, which leads to the classic double-response failure:
the server tries to handle the same request twice
In short, a non-critical cleanup failure could escalate into a runtime response-state error.
Related issue
Type of change
How to test
cd faas && npm test.Fix: packageUpload Async Cleanup Error Handlingsuite passes.Checklist
Note:
The guard is intentionally narrow. It does not hide upload failures that happen before the response is sent. It only prevents late asynchronous cleanup errors from re-entering Express after the request has already been settled.
Release notes
Fixed package upload so late async cleanup failures no longer trigger a second response attempt after success.