node/test/parallel/test-http-client-abort3.js
Robert Nagy fe43bd8ddd 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>
2021-02-03 23:05:34 +01:00

33 lines
672 B
JavaScript

'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();
}