Skip to content

Commit 7b792cf

Browse files
authored
implement memory leak fix from http-proxy (#566)
1 parent b5d7dd0 commit 7b792cf

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

app/steps/sendProxyRequest.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var chunkLength = require('../../lib/chunkLength');
44

55
function defaultSendProxyRequest(Container) {
66
var req = Container.user.req;
7+
var res = Container.user.res;
78
var bodyContent = Container.proxy.bodyContent;
89
var reqOpt = Container.proxy.reqBuilder;
910
var options = Container.options;
@@ -67,11 +68,25 @@ function defaultSendProxyRequest(Container) {
6768
req.pipe(proxyReq);
6869
}
6970

70-
req.on('aborted', function () {
71-
// reject?
71+
// 'aborted' event stopped working reliably on v15.5.0 and was later removed entirely
72+
var supportsAbortedEvent = (function () {
73+
var ver = process.versions.node.split('.').map(Number);
74+
return ver[0] <= 14 || ver[0] === 15 && ver[1] <= 4;
75+
}());
7276

73-
proxyReq.abort();
74-
});
77+
if (supportsAbortedEvent) {
78+
req.on('aborted', function () {
79+
// reject?
80+
proxyReq.abort();
81+
});
82+
} else {
83+
res.on('close', function () {
84+
var aborted = !res.writableFinished;
85+
if (aborted) {
86+
proxyReq.abort();
87+
}
88+
});
89+
}
7590
});
7691
}
7792

0 commit comments

Comments
 (0)