fix: improve proxy error handling by adding listeners for request, response, and proxy stream failures
Browse files- health-server.js +27 -8
health-server.js
CHANGED
|
@@ -629,17 +629,36 @@ const server = http.createServer(async (req, res) => {
|
|
| 629 |
(proxyRes) => {
|
| 630 |
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
| 631 |
proxyRes.pipe(res);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
},
|
| 633 |
);
|
| 634 |
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
});
|
| 644 |
|
| 645 |
req.pipe(proxyReq);
|
|
|
|
| 629 |
(proxyRes) => {
|
| 630 |
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
| 631 |
proxyRes.pipe(res);
|
| 632 |
+
proxyRes.on("error", (err) => {
|
| 633 |
+
console.error("proxyRes error:", err);
|
| 634 |
+
res.end();
|
| 635 |
+
});
|
| 636 |
},
|
| 637 |
);
|
| 638 |
|
| 639 |
+
req.on("error", (err) => {
|
| 640 |
+
console.error("req error:", err);
|
| 641 |
+
proxyReq.destroy();
|
| 642 |
+
});
|
| 643 |
+
|
| 644 |
+
res.on("error", (err) => {
|
| 645 |
+
console.error("res error:", err);
|
| 646 |
+
proxyReq.destroy();
|
| 647 |
+
});
|
| 648 |
+
|
| 649 |
+
proxyReq.on("error", (err) => {
|
| 650 |
+
console.error("proxyReq error:", err);
|
| 651 |
+
if (!res.headersSent) {
|
| 652 |
+
res.writeHead(503, { "Content-Type": "application/json" });
|
| 653 |
+
res.end(
|
| 654 |
+
JSON.stringify({
|
| 655 |
+
status: "starting",
|
| 656 |
+
message: "n8n is initializing... or connection failed",
|
| 657 |
+
}),
|
| 658 |
+
);
|
| 659 |
+
} else {
|
| 660 |
+
res.end();
|
| 661 |
+
}
|
| 662 |
});
|
| 663 |
|
| 664 |
req.pipe(proxyReq);
|