forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
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 nodejs#27477, a full backport would require also nodejs#25094 which has a dont-land-on-v10.x label on it. Fixes: nodejs#26961
- Loading branch information
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))); | ||
} |