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
http: remove duplicate async_hooks init for http parser #23263
Closed
basti1302
wants to merge
2
commits into
nodejs:master
from
basti1302:fix-missing-async-hooks-destroy-http-parser
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,27 @@ | |
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const FreeList = require('internal/freelist'); | ||
const { FreeList } = require('internal/freelist'); | ||
|
||
assert.strictEqual(typeof FreeList, 'function'); | ||
|
||
const flist1 = new FreeList('flist1', 3, String); | ||
const flist1 = new FreeList('flist1', 3, Object); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One downside of this change is that the items in freelist can no longer be primitives, since we attach an attribute to it. But as the freelist is only used for HTTP parsers anyway, I don't think it is an issue. |
||
|
||
// 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'); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This very much looks like the output of verify-graph#printGraph has simply been copied here without giving it much thought. The duplicated HTTPPARSER init calls were showing here and don't make much sense, IMO.