Fix handling of client disconnect so that econnreset event is emitted instead of error#1542
Fix handling of client disconnect so that econnreset event is emitted instead of error#1542gsf4726 wants to merge 1 commit intohttp-party:masterfrom
Conversation
… instead of error
|
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. |
|
Fix works great. I have been using it on my project. Would be awesome to see this merged in! Please.... :) |
|
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 🤦 |
|
As this project is dead, we had to apply this change with https://www.npmjs.com/package/patch-package, thanks for the solution @gsf4726 |
|
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');
} |
Check `!req.socket?.writable` instead of `req.socket.destroyed` in the proxy error handler. The socket `writable` flag is set to false earlier than `destroyed` during client disconnection, avoiding a race condition where ECONNRESET errors were incorrectly routed to the `error` event. Ref: http-party/node-http-proxy#1542
|
This issue has been fixed in unjs/httpxy#115. |
Check `!req.socket?.writable` instead of `req.socket.destroyed` in the proxy error handler. The socket `writable` flag is set to false earlier than `destroyed` during client disconnection, avoiding a race condition where ECONNRESET errors were incorrectly routed to the `error` event. Ref: http-party/node-http-proxy#1542
Check `!req.socket?.writable` instead of `req.socket.destroyed` in the proxy error handler. The socket `writable` flag is set to false earlier than `destroyed` during client disconnection, avoiding a race condition where ECONNRESET errors were incorrectly routed to the `error` event. Ref: http-party/node-http-proxy#1542
Fixes #1455