From 7e573a2ff727134326f1edf25bb11684801898ff Mon Sep 17 00:00:00 2001 From: Ayush Jhanwar Date: Thu, 10 Sep 2026 15:58:24 +0530 Subject: [PATCH] fix(worker): don't crash the worker when /metrics collection fails The /metrics error handler passed a raw Error object to res.end(), which only accepts a string or Buffer. When a metric collector rejects (e.g. a Redis error during a failover), res.end(error) throws a TypeError inside the catch that is unhandled and exits the process. Because /metrics is scraped on every pod, a single failing collector can crash the whole worker fleet at once. Stringify the error so a metrics failure returns a clean 500 instead. --- apps/worker/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/worker/src/index.ts b/apps/worker/src/index.ts index 0a38bffa2..3b9100e8a 100644 --- a/apps/worker/src/index.ts +++ b/apps/worker/src/index.ts @@ -78,7 +78,11 @@ async function start() { res.end(metrics); }) .catch((error) => { - res.status(500).end(error); + // res.end() only accepts a string/Buffer; passing a raw Error object + // throws a TypeError inside this catch, which is unhandled and crashes + // the worker. Since /metrics is scraped on every pod, one failing + // collector can take down the whole fleet. Stringify to be safe. + res.status(500).end(String(error?.message ?? error)); }); });