mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
test: prevent parser reuse across close scenarios
Both cases replace parser cleanup methods. Faster socket cleanup can return a modified parser to the shared pool and close it before the other request uses it. Run the immediate and deferred close cases in separate test files so each gets its own process and parser pool. Preserve both cleanup paths and all call-count assertions. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66017 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
efc612d891
commit
5c5bd227b0
2 files changed
+45
-32
No files matched your search
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const http = require('http');
|
||||
|
||||
// Keep this case in a separate process from the immediate-close case so
|
||||
// their modified parsers cannot be reused across cases.
|
||||
|
||||
function request(server) {
|
||||
http.get({
|
||||
agent: false,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
}, (res) => {
|
||||
res.resume();
|
||||
});
|
||||
}
|
||||
|
||||
const server = http.createServer(common.mustCallAtLeast((req, res) => {
|
||||
// See `freeParser` in _http_common.js
|
||||
const { parser } = req.socket;
|
||||
parser.free = common.mustCall(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
parser.close();
|
||||
}));
|
||||
});
|
||||
req.socket.on('close', common.mustCall(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
server.close();
|
||||
}));
|
||||
}));
|
||||
res.end('ok');
|
||||
})).listen(0, common.mustCall(() => {
|
||||
request(server);
|
||||
}));
|
||||
@@ -13,36 +13,14 @@ function request(server) {
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const server = http.createServer(common.mustCallAtLeast((req, res) => {
|
||||
// Hack to not remove parser out of server.connectionList
|
||||
// See `freeParser` in _http_common.js
|
||||
req.socket.parser.free = common.mustCall();
|
||||
req.socket.on('close', common.mustCall(() => {
|
||||
server.close();
|
||||
}));
|
||||
res.end('ok');
|
||||
})).listen(0, common.mustCall(() => {
|
||||
request(server);
|
||||
const server = http.createServer(common.mustCallAtLeast((req, res) => {
|
||||
// Hack to not remove parser out of server.connectionList
|
||||
// See `freeParser` in _http_common.js
|
||||
req.socket.parser.free = common.mustCall();
|
||||
req.socket.on('close', common.mustCall(() => {
|
||||
server.close();
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const server = http.createServer(common.mustCallAtLeast((req, res) => {
|
||||
// See `freeParser` in _http_common.js
|
||||
const { parser } = req.socket;
|
||||
parser.free = common.mustCall(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
parser.close();
|
||||
}));
|
||||
});
|
||||
req.socket.on('close', common.mustCall(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
server.close();
|
||||
}));
|
||||
}));
|
||||
res.end('ok');
|
||||
})).listen(0, common.mustCall(() => {
|
||||
request(server);
|
||||
}));
|
||||
}
|
||||
res.end('ok');
|
||||
})).listen(0, common.mustCall(() => {
|
||||
request(server);
|
||||
}));
|
||||
Reference in new issue
Block a user