mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
http: fix ClientRequest unhandled errors
ClientRequest could someone cause an unhandled error from socket. Fixes: https://github.com/nodejs/node/issues/36931 PR-URL: https://github.com/nodejs/node/pull/36970 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
@@ -801,13 +801,15 @@ function onSocketNT(req, socket, err) {
|
||||
req.emit('close');
|
||||
}
|
||||
|
||||
if (!err && req.agent) {
|
||||
socket?.emit('free');
|
||||
} else if (socket) {
|
||||
finished(socket.destroy(err || req[kError]), (er) => {
|
||||
_destroy(req, er || err);
|
||||
});
|
||||
return;
|
||||
if (socket) {
|
||||
if (!err && req.agent && !socket.destroyed) {
|
||||
socket.emit('free');
|
||||
} else {
|
||||
finished(socket.destroy(err || req[kError]), (er) => {
|
||||
_destroy(req, er || err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_destroy(req, err || req[kError]);
|
||||
|
||||
32
test/parallel/test-http-client-abort3.js
Normal file
32
test/parallel/test-http-client-abort3.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
|
||||
function createConnection() {
|
||||
const socket = new net.Socket();
|
||||
|
||||
process.nextTick(function() {
|
||||
socket.destroy(new Error('Oops'));
|
||||
});
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
{
|
||||
const req = http.get({ createConnection });
|
||||
|
||||
req.on('error', common.expectsError({ name: 'Error', message: 'Oops' }));
|
||||
req.abort();
|
||||
}
|
||||
|
||||
{
|
||||
class CustomAgent extends http.Agent {}
|
||||
CustomAgent.prototype.createConnection = createConnection;
|
||||
|
||||
const req = http.get({ agent: new CustomAgent() });
|
||||
|
||||
req.on('error', common.expectsError({ name: 'Error', message: 'Oops' }));
|
||||
req.abort();
|
||||
}
|
||||
Reference in New Issue
Block a user