-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_hooks: avoid double-destroy HTTPParser
Avoid that destroy hook is invoked twice - once via `Parser::Free()` and once again via `Parser::Reinitialize()` by clearing the async_id in `EmitDestroy()`. Partial backport of #27477, a full backport would require also #25094 which has a dont-land-on-v10.x label on it. Fixes: #26961 Backport-PR-URL: #27986 PR-URL: #27477 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]>
- Loading branch information
1 parent
08a32fb
commit 65ef26f
Showing
4 changed files
with
80 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
test/parallel/test-async-hooks-http-parser-nodouble-destroy.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { createHook } = require('async_hooks'); | ||
const http = require('http'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/19859. | ||
// Checks that matching destroys are emitted when creating new/reusing old http | ||
// parser instances. | ||
|
||
const httpParsers = []; | ||
const dupDestroys = []; | ||
const destroyed = []; | ||
|
||
createHook({ | ||
init(asyncId, type, triggerAsyncId, resource) { | ||
if (type === 'HTTPPARSER') { | ||
httpParsers.push(asyncId); | ||
} | ||
}, | ||
destroy(asyncId) { | ||
if (destroyed.includes(asyncId)) { | ||
dupDestroys.push(asyncId); | ||
} else { | ||
destroyed.push(asyncId); | ||
} | ||
} | ||
}).enable(); | ||
|
||
const server = http.createServer((req, res) => { | ||
res.end(); | ||
}); | ||
|
||
server.listen(common.mustCall(() => { | ||
http.get({ port: server.address().port }, common.mustCall(() => { | ||
server.close(common.mustCall(() => { | ||
server.listen(common.mustCall(() => { | ||
http.get({ port: server.address().port }, common.mustCall(() => { | ||
server.close(common.mustCall(() => { | ||
setTimeout(common.mustCall(verify), 200); | ||
})); | ||
})); | ||
})); | ||
})); | ||
})); | ||
})); | ||
|
||
function verify() { | ||
assert.strictEqual(httpParsers.length, 4); | ||
|
||
assert.strictEqual(dupDestroys.length, 0); | ||
httpParsers.forEach((id) => assert.ok(destroyed.includes(id))); | ||
} |