node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Fix handling of client disconnect so that econnreset event is emitted instead of error

Open gsf4726 opened this issue 3 years ago • 5 comments

Fixes #1455

gsf4726 avatar Jul 21 '21 11:07 gsf4726

Thank you so much for this fix; this issue has been the bane of my life for weeks and your solution totally fixes it. Would love to see this merged ASAP so I don't have to keep on modifying my local http-proxy files.

edspencer avatar Oct 13 '21 20:10 edspencer

Fix works great. I have been using it on my project. Would be awesome to see this merged in! Please.... :)

franckc avatar Oct 19 '21 20:10 franckc

Looks like this project is dead, so in order to use this fix we just forked the project and made the 1 line change in this PR. It seems to work for us. Took about 30 mins, but better than manually editing that file in node_modules 🤦

edspencer avatar Nov 19 '21 20:11 edspencer

As this project is dead, we had to apply this change with https://www.npmjs.com/package/patch-package, thanks for the solution @gsf4726

ReyRod avatar Dec 07 '21 13:12 ReyRod

Monkey patching function for who don't want to use the patch-package.

function monkeyPatchHttpProxyLibrary() {
  // https://github.com/http-party/node-http-proxy/pull/1542
  const filePath = path.join(
    __dirname,
    '../node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js',
  );
  const fileContent = fs.readFileSync(filePath, 'utf-8');
  const patchedFileContent = fileContent.replace(
    `if (req.socket.destroyed && err.code === 'ECONNRESET') {`,
    `if (req.aborted && err.code === 'ECONNRESET') {`,
  );
  fs.writeFileSync(filePath, patchedFileContent, 'utf-8');
}

sidx1024 avatar Sep 15 '22 10:09 sidx1024