-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: fix ClientRequest unhandled errors
ClientRequest could someone cause an unhandled error from socket. Fixes: #36931 PR-URL: #36970 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
1 parent
b87c0d6
commit 4cdc5ea
Showing
2 changed files
with
41 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |