Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion apps/insights/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ import { Worker } from "bullmq";
import { processInsightsJob } from "./jobs";
import { emitInsightsEvent } from "./lib/evlog-insights";

// These Redis errors are transient — they occur during failover or server
// upgrade and the BullMQ worker reconnects automatically (maxRetriesPerRequest:
// null). Logging them at WARN prevents false-positive ERROR incidents.
const TRANSIENT_REDIS_ERROR_PATTERNS = [
/^READONLY /,
/^ERR caller gone/,
/ECONNRESET/,
/Connection is closed/,
/Socket closed unexpectedly/,
];

function isTransientRedisError(error: Error): boolean {
return TRANSIENT_REDIS_ERROR_PATTERNS.some((pattern) =>
pattern.test(error.message)
);
}
Comment on lines +23 to +27

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 isTransientRedisError is unexported and untested

The patterns in TRANSIENT_REDIS_ERROR_PATTERNS are the sole gate between WARN and ERROR alerting. There is no worker.test.ts, and the function is unexported, so there is currently no way to verify that the regexes correctly match the intended Redis messages (e.g. READONLY Writes are temporarily rejected…) and do not accidentally match unrelated errors. If a pattern is wrong or a Redis error message format changes, operators would silently receive WARN for a real incident with no indication anything is wrong. Exporting isTransientRedisError (or the pattern list) and adding a few unit tests would make the boundary explicit and regression-proof.


const DEFAULT_INSIGHTS_WORKER_CONCURRENCY = 5;

export function getInsightsWorkerConcurrency(
Expand Down Expand Up @@ -77,7 +94,8 @@ export function startInsightsWorker() {
});

worker.on("error", (error) => {
emitInsightsEvent("error", "worker.error", {
const level = isTransientRedisError(error) ? "warn" : "error";
emitInsightsEvent(level, "worker.error", {
error_message: error.message,
error_stack: error.stack,
});
Expand Down