child_process: fix leak when passing http sockets#20305
child_process: fix leak when passing http sockets#20305santigimeno wants to merge 1 commit intonodejs:masterfrom
Conversation
After passing an HTTP socket, release its associated resources. Fixes: nodejs#15651
|
/cc @gireeshpunathil @nodejs/child_process |
|
thanks, will test and let you know. |
|
Unfortunately I am unable to see any difference: without the changes: (I am printing only the usedHeap value, because that is the one which matters) with the change: |
|
@gireeshpunathil What test code are you using? Thanks |
|
#cat s.js const http = require('http');
const { fork } = require('child_process');
const server = http.createServer((req, res) => {
const workerProcess = fork('worker.js', [], {execArgv: []});
workerProcess.on('message', (status) => {
switch (status) {
case 'ready':
workerProcess.send({
method: req.method,
headers: req.headers,
path: req.path,
httpVersionMajor: req.httpVersionMajor,
query: req.query,
}, res.socket);
break;
case 'done':
res.socket.end();
}
});
});
server.listen(8080);
setInterval(() => {
console.log(process.memoryUsage().heapUsed)
}, 10000);#cat worker.js const http = require('http');
process.on('message', (req, socket) => {
const res = new http.ServerResponse(req);
res._finish = function _finish() {
res.emit('prefinish');
socket.end();
};
res.assignSocket(socket);
socket.once('finish', () => {
process.send('done', () => {
process.exit(0);
});
});
res.end(process.pid.toString());
});
process.send('ready'); |
|
@gireeshpunathil I'm not seeing that behavior. With the patch, I've been running the code locally for an hour an the P.S. I've been using your code along with the test runner in https://github.com/Reggino/node-issue-15651-test |
|
I did further testing, and able to see what you saw:
thanks, LGTM! |
After passing an HTTP socket, release its associated resources. PR-URL: nodejs#20305 Fixes: nodejs#15651 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
Landed in 511230f 🎉 |
After passing an HTTP socket, release its associated resources.
Fixes: #15651
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes