diegosouzapw/OmniRoute · error

[SESSION_AFFINITY] Startup cleanup failed:

Error message

[SESSION_AFFINITY] Startup cleanup failed:

What it means

The one-time startup cleanup of stale session-account affinity records (expired entries in the key_value namespace) threw. Non-fatal to startup; stale affinity records persist and may route sessions to connections they previously used until the periodic cleanup succeeds in removing them.

Solutions

  1. Inspect the logged error (often a DB lock during startup)
  2. Wait for the periodic cleanup interval to retry removal
  3. Manually purge expired affinity rows if the error persists
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/lib/db/sessionAccountAffinity.ts:195 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/c3e241d2a44ee9a3. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/sessionAccountAffinity.ts:195

      const record = parseRecord(row.value);
      if (!record || Date.parse(record.expiresAt) <= now) {
        db.prepare("DELETE FROM key_value WHERE namespace = ? AND key = ?").run(NAMESPACE, row.key);
        deleted++;
      }
    }
  });

  tx();
  return deleted;
}

export function startSessionAccountAffinityCleanup(): void {
  if (cleanupTimer) return;

  try {
    cleanupStaleSessionAccountAffinities();
  } catch (error) {
    console.warn("[SESSION_AFFINITY] Startup cleanup failed:", error);
  }

  cleanupTimer = setInterval(() => {
    try {
      cleanupStaleSessionAccountAffinities();
    } catch (error) {
      console.warn("[SESSION_AFFINITY] Periodic cleanup failed:", error);
    }
  }, CLEANUP_INTERVAL_MS);
  if (typeof cleanupTimer === "object" && "unref" in cleanupTimer) cleanupTimer.unref?.();
}

export function stopSessionAccountAffinityCleanupForTests(): void {
  if (!cleanupTimer) return;
  clearInterval(cleanupTimer);
  cleanupTimer = null;
}

View on GitHub (pinned to a179ffed5b)