Skip to content

Commit

Permalink
Revert "Do not double send the response if the request is destroyed b…
Browse files Browse the repository at this point in the history
…ut not aborted (#4963)"

This reverts commit c235d2d.
  • Loading branch information
mcollina committed Aug 31, 2023
1 parent 9b3ca58 commit 259d2e5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
5 changes: 1 addition & 4 deletions lib/wrapThenable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ function wrapThenable (thenable, reply) {
// the request may be terminated during the reply. in this situation,
// it require an extra checking of request.aborted to see whether
// the request is killed by client.
// Most of the times aborted will be true when destroyed is true,
// however there is a race condition where the request is not
// aborted but only destroyed.
if (payload !== undefined || (reply.sent === false && reply.raw.headersSent === false && reply.request.raw.aborted === false && reply.request.raw.destroyed === false)) {
if (payload !== undefined || (reply.sent === false && reply.raw.headersSent === false && reply.request.raw.aborted === false)) {
// we use a try-catch internally to avoid adding a catch to another
// promise, increase promise perf by 10%
try {
Expand Down
22 changes: 0 additions & 22 deletions test/wrapThenable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,3 @@ test('should reject immediately when reply[kReplyHijacked] is true', t => {
const thenable = Promise.reject(new Error('Reply sent already'))
wrapThenable(thenable, reply)
})

test('should not send the payload if the raw socket was destroyed but not aborted', async t => {
const reply = {
sent: false,
raw: {
headersSent: false
},
request: {
raw: {
aborted: false,
destroyed: true
}
},
send () {
t.fail('should not send')
}
}
const thenable = Promise.resolve()
wrapThenable(thenable, reply)

await thenable
})

0 comments on commit 259d2e5

Please sign in to comment.