-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
http: remove duplicate async_hooks init for http parser #23263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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: #19859
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,20 +38,14 @@ process.on('exit', function() { | |
| { type: 'HTTPPARSER', | ||
| id: 'httpparser:1', | ||
| triggerAsyncId: 'tcpserver:1' }, | ||
| { type: 'HTTPPARSER', | ||
| id: 'httpparser:2', | ||
| triggerAsyncId: 'tcpserver:1' }, | ||
| { type: 'TCPWRAP', id: 'tcp:2', triggerAsyncId: 'tcpserver:1' }, | ||
| { type: 'Timeout', id: 'timeout:1', triggerAsyncId: 'tcp:2' }, | ||
| { type: 'HTTPPARSER', | ||
| id: 'httpparser:3', | ||
| triggerAsyncId: 'tcp:2' }, | ||
| { type: 'HTTPPARSER', | ||
| id: 'httpparser:4', | ||
| id: 'httpparser:2', | ||
| triggerAsyncId: 'tcp:2' }, | ||
| { type: 'Timeout', | ||
| id: 'timeout:2', | ||
| triggerAsyncId: 'httpparser:4' }, | ||
| triggerAsyncId: 'httpparser:2' }, | ||
| { type: 'SHUTDOWNWRAP', | ||
| id: 'shutdown:1', | ||
| triggerAsyncId: 'tcp:2' } ] | ||
|
||
|
|
||
| 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(); | ||
| }); | ||
| })(); | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,24 +8,23 @@ const FreeList = require('internal/freelist'); | |
|
|
||
| assert.strictEqual(typeof FreeList, 'function'); | ||
|
|
||
| const flist1 = new FreeList('flist1', 3, String); | ||
| const flist1 = new FreeList('flist1', 3, Object); | ||
|
||
|
|
||
| // Allocating when empty, should not change the list size | ||
| const result = flist1.alloc('test'); | ||
| assert.strictEqual(typeof result, 'string'); | ||
| assert.strictEqual(result, 'test'); | ||
| const result = flist1.alloc(); | ||
| assert.strictEqual(typeof result, 'object'); | ||
| assert.strictEqual(flist1.list.length, 0); | ||
|
|
||
| // Exhaust the free list | ||
| assert(flist1.free('test1')); | ||
| assert(flist1.free('test2')); | ||
| assert(flist1.free('test3')); | ||
| assert(flist1.free({ id: 'test1' })); | ||
| assert(flist1.free({ id: 'test2' })); | ||
| assert(flist1.free({ id: 'test3' })); | ||
|
|
||
| // Now it should not return 'true', as max length is exceeded | ||
| assert.strictEqual(flist1.free('test4'), false); | ||
| assert.strictEqual(flist1.free('test5'), false); | ||
| assert.strictEqual(flist1.free({ id: 'test4' }), false); | ||
| assert.strictEqual(flist1.free({ id: 'test5' }), false); | ||
|
|
||
| // At this point 'alloc' should just return the stored values | ||
| assert.strictEqual(flist1.alloc(), 'test3'); | ||
| assert.strictEqual(flist1.alloc(), 'test2'); | ||
| assert.strictEqual(flist1.alloc(), 'test1'); | ||
| assert.strictEqual(flist1.alloc().id, 'test3'); | ||
| assert.strictEqual(flist1.alloc().id, 'test2'); | ||
| assert.strictEqual(flist1.alloc().id, 'test1'); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use a symbol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.