Skip to content

Commit 2df834c

Browse files
committed
fix #5 -- ECONNRESET due to upstream timeout causes crash -- *maybe*
Logically I believe this should fix it, but I didn't reproduce the problem. That said, clearly our http-proxy-3 should attach an error handler to the websocket, as is done here and explained in the comment.
1 parent 196e398 commit 2df834c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/http-proxy/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ export class ProxyServer extends EventEmitter {
115115
log("proxy: ", { type, path: req.url });
116116
const res = args[1];
117117
const passes = type === "ws" ? this.wsPasses : this.webPasses;
118+
if (type == "ws") {
119+
// socket -- proxy websocket errors to our error handler;
120+
// see https://github.com/sagemathinc/http-proxy-3/issues/5
121+
// NOTE: as mentioned below, res is the socket in this case.
122+
// One of the passes does add an error handler, but there's no
123+
// guarantee we even get to that pass before something bad happens,
124+
// and there's no way for a user of http-proxy-3 to get ahold
125+
// of this res object and attach their own error handler until
126+
// after the passes. So we better attach one ASAP right here:
127+
res.on("error", (...args) => {
128+
this.emit("error", ...args);
129+
});
130+
}
118131
let counter = args.length - 1;
119132
let head;
120133
let cb;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-proxy-3",
3-
"version": "1.20.6",
3+
"version": "1.20.7",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/sagemathinc/http-proxy-3.git"

0 commit comments

Comments
 (0)