Skip to content

Commit 6c85753

Browse files
committed
close the connecting socket when request errored
1 parent 176d4b4 commit 6c85753

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
7878
} else {
7979
socket = net.connect(proxy);
8080
}
81-
81+
82+
// when request timeouted or occured other errors,
83+
// we need to close the socket which is still connecting to the proxy
84+
req.on('error',onreqerror);
85+
86+
function onreqerror(err){
87+
socket.destroy();
88+
onerror(err);
89+
}
90+
8291
// we need to buffer any HTTP traffic that happens with the proxy before we get
8392
// the CONNECT response, so that if the response is anything other than an "200"
8493
// response code, then we can re-play the "data" events on the socket once the
@@ -93,6 +102,7 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
93102
}
94103

95104
function cleanup() {
105+
req.removeListener('error', onreqerror);
96106
socket.removeListener('end', onend);
97107
socket.removeListener('error', onerror);
98108
socket.removeListener('close', onclose);

0 commit comments

Comments
 (0)