forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: remove duplicate async_hooks init for http parser
Each time a new parser was created, AsyncReset was being called via the C++ Parser class constructor (super constructor AsyncWrap) and also via Parser::Reinitialize. This also adds a missing async_hooks destroy event before AsyncReset is called for the parser reuse case, otherwise the old async_id never gets destroyed. Refs: nodejs#19859
- Loading branch information
Showing
10 changed files
with
113 additions
and
31 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
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
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,61 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const Countdown = require('../common/countdown'); | ||
const assert = require('assert'); | ||
const async_hooks = 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 N = 50; | ||
const KEEP_ALIVE = 100; | ||
|
||
const createdIds = []; | ||
const destroyedIds = []; | ||
async_hooks.createHook({ | ||
init: common.mustCallAtLeast((asyncId, type) => { | ||
if (type === 'HTTPPARSER') { | ||
createdIds.push(asyncId); | ||
} | ||
}, N), | ||
destroy: (asyncId) => { | ||
destroyedIds.push(asyncId); | ||
} | ||
}).enable(); | ||
|
||
const server = http.createServer(function(req, res) { | ||
res.end('Hello'); | ||
}); | ||
|
||
const keepAliveAgent = new http.Agent({ | ||
keepAlive: true, | ||
keepAliveMsecs: KEEP_ALIVE, | ||
}); | ||
|
||
const countdown = new Countdown(N, () => { | ||
server.close(() => { | ||
// give the server sockets time to close (which will also free their | ||
// associated parser objects) after the server has been closed. | ||
setTimeout(() => { | ||
createdIds.forEach((createdAsyncId) => { | ||
assert.ok(destroyedIds.indexOf(createdAsyncId) >= 0); | ||
}); | ||
}, KEEP_ALIVE * 2); | ||
}); | ||
}); | ||
|
||
server.listen(0, function() { | ||
for (let i = 0; i < N; ++i) { | ||
(function makeRequest() { | ||
http.get({ | ||
port: server.address().port, | ||
agent: keepAliveAgent | ||
}, function(res) { | ||
countdown.dec(); | ||
res.resume(); | ||
}); | ||
})(); | ||
} | ||
}); |
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