Skip to content

Open-source status page, incident response and uptime monitoring

fix: memory leak ? (#2172)

Thibault Le Ouaye14f62d1ce0c
diff --git a/apps/workflows/src/cron/checker.ts b/apps/workflows/src/cron/checker.ts
index 6f6483dc0..edcf7a4cd 100644
--- a/apps/workflows/src/cron/checker.ts
+++ b/apps/workflows/src/cron/checker.ts
@@ -28,7 +28,6 @@ import {
import { regionDict } from "@openstatus/regions";
import { db } from "../lib/db";
-import { getSentry } from "@hono/sentry";
import { getLogger } from "@logtape/logtape";
import type { monitorPeriodicitySchema } from "@openstatus/db/src/schema/constants";
import {
@@ -37,7 +36,6 @@ import {
type tpcPayloadSchema,
transformHeaders,
} from "@openstatus/utils";
-import type { Context } from "hono";
import { env } from "../env";
type TaskInput = {
@@ -64,8 +62,7 @@ const client = new CloudTasksClient({
export async function sendCheckerTasks(
periodicity: z.infer<typeof monitorPeriodicitySchema>,
- c: Context,
-) {
+): Promise<{ success: number; failed: number }> {
const parent = client.queuePath(
env().GCP_PROJECT_ID,
env().GCP_LOCATION,
@@ -121,7 +118,7 @@ export async function sendCheckerTasks(
if (monitors.data.length === 0) {
logger.info("No monitors to check", { periodicity });
- return;
+ return { success: 0, failed: 0 };
}
// Batch fetch all monitor statuses in a single query (N+1 fix)
@@ -235,11 +232,9 @@ export async function sendCheckerTasks(
failed_count: failed,
success_count: success,
});
- getSentry(c).captureMessage(
- `sendCheckerTasks for ${periodicity} ended with ${failed} failed tasks`,
- "error",
- );
}
+
+ return { success, failed };
}
// timestamp needs to be in ms
const createCronTask = async (
diff --git a/apps/workflows/src/cron/external-status.ts b/apps/workflows/src/cron/external-status.ts
index da2cfaac2..489c00357 100644
--- a/apps/workflows/src/cron/external-status.ts
+++ b/apps/workflows/src/cron/external-status.ts
@@ -13,6 +13,8 @@ import { db } from "../lib/db";
const logger = getLogger(["workflow", "external-status"]);
+const tb = new OSTinybird(env().TINY_BIRD_API_KEY);
+
function toStatusPageEntry(row: ExternalServiceRow): StatusPageEntry {
return {
id: row.slug,
@@ -58,7 +60,6 @@ export async function runExternalStatusTick(): Promise<{
failureCount: number;
total: number;
}> {
- const tb = new OSTinybird(env().TINY_BIRD_API_KEY);
const services = await listExternalServices({ ctx: { db } });
const entries = services.map(toStatusPageEntry);
diff --git a/apps/workflows/src/cron/index.ts b/apps/workflows/src/cron/index.ts
index 187137a31..d64b15b25 100644
--- a/apps/workflows/src/cron/index.ts
+++ b/apps/workflows/src/cron/index.ts
@@ -40,21 +40,27 @@ app.get("/checker/:period", async (c) => {
void Effect.runPromise(
Effect.tryPromise({
- try: () => sendCheckerTasks(schema.data, c),
+ try: () => sendCheckerTasks(schema.data),
catch: (e) => new Error(`Error in /checker/${period} cron: ${e}`),
}).pipe(
Effect.retry({
times: 3,
schedule: Schedule.exponential("1000 millis"),
}),
- Effect.tap(() =>
- Effect.sync(() =>
+ Effect.tap((result) =>
+ Effect.sync(() => {
+ if (result.failed > 0) {
+ sentry.captureMessage(
+ `sendCheckerTasks for ${period} ended with ${result.failed} failed tasks`,
+ "error",
+ );
+ }
sentry.captureCheckIn({
checkInId,
monitorSlug: period,
status: "ok",
- }),
- ),
+ });
+ }),
),
Effect.catchAll((e) =>
Effect.sync(() => {
diff --git a/apps/workflows/src/index.ts b/apps/workflows/src/index.ts
index a58d242ff..db3e15d9a 100644
--- a/apps/workflows/src/index.ts
+++ b/apps/workflows/src/index.ts
@@ -47,7 +47,7 @@ function shouldSample(event: Record<string, unknown>): boolean {
if (statusCode && statusCode >= 500) return true;
// Always capture: explicit errors
- if (event.error) return true;
+ if (event.outcome === "error") return true;
// Always capture: slow requests (above p99 - 2s threshold)
if (durationMs && durationMs > 2000) return true;
@@ -138,16 +138,7 @@ app.use("*", async (c, next) => {
const duration = Date.now() - startTime;
event.status_code = c.res.status;
- if (c.error) {
- event.outcome = "error";
- event.error = {
- type: c.error.name,
- message: c.error.message,
- stack: c.error.stack,
- };
- } else {
- event.outcome = "success";
- }
+ event.outcome = c.error ? "error" : "success";
event.duration_ms = duration;
// Emit canonical log line with all context (wide event pattern)
if (shouldSample(event)) {