fix: destroy request object after successful response (issue #1489) #2187
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.
Checklist
Based on my testing this fixes #1489 for v11: late
ECONNRESET
errors no longer causes the "onCancel handler was attached after the promise settled" error. (I used this gist for testing).It mimics what is done in v12 by calling
request.destroy()
after a successful response right before the promise is resolved.I tried to add a test case where the server would reset the TCP connection and cause an ECONNRESET error after sending a success response but that proved to be challenging to do using an Express server. I also tried using a Python server executed from the test case but it proved to be too brittle to be a good test case. Therefore I landed on a simpler test case that ensures that the request has been destroyed once the promise has successfully resolved.