From bba70955734cbcfc0f441f478b0a4c826280b448 Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Ducasse Date: Wed, 23 Sep 2026 09:40:29 +0200 Subject: [PATCH] server: fix env --- apps/server/fly.toml | 6 ++++++ apps/server/src/libs/middlewares/limits.ts | 6 ++++++ deno.lock | 3 +-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/server/fly.toml b/apps/server/fly.toml index 980dedde..456af16d 100644 --- a/apps/server/fly.toml +++ b/apps/server/fly.toml @@ -23,6 +23,9 @@ primary_region = "ams" min_machines_running = 1 processes = ["app"] +# Keep `soft_limit` < `API_MAX_IN_FLIGHT` (see `[env]`) <= `hard_limit`. If the +# app's cap sits below `soft_limit` the two guards fight: the app sheds 503s +# while Fly still reads the machine as having room and never starts a peer. [http_service.concurrency] type = "requests" hard_limit = 1000 @@ -41,6 +44,9 @@ primary_region = "ams" [env] NODE_ENV = "production" PORT = "3000" + # Backstop only. Fly stops routing here at `hard_limit`, so the in-flight + # guard should fire only once that has already failed to protect the machine. + API_MAX_IN_FLIGHT = "1000" # [checks] diff --git a/apps/server/src/libs/middlewares/limits.ts b/apps/server/src/libs/middlewares/limits.ts index 0c5d6b57..69904d93 100644 --- a/apps/server/src/libs/middlewares/limits.ts +++ b/apps/server/src/libs/middlewares/limits.ts @@ -2,6 +2,12 @@ import { env } from "@/env"; /** `skipValidation` hands back raw strings, so coerce; missing, non-numeric or zero values fall back. */ export const limits = { + /** + * Conservative default for self-hosted single-container deploys. Fly + * production overrides it from `apps/server/fly.toml`, where it must stay + * above `soft_limit` and at most `hard_limit` so Fly scales out before the + * app starts shedding. + */ maxInFlight: Number(env.API_MAX_IN_FLIGHT) || 128, perMinute: Number(env.API_RATE_LIMIT_PER_MINUTE) || 600, burstPer10s: Number(env.API_RATE_LIMIT_BURST_PER_10S) || 100, diff --git a/deno.lock b/deno.lock index 1fc5ffec..58ec016a 100644 --- a/deno.lock +++ b/deno.lock @@ -112,8 +112,7 @@ "packageJson": { "dependencies": [ "npm:@jsr/std__expect@^1.0.19", - "npm:@jsr/std__testing@^1.0.19", - "npm:marked@15.0.12" + "npm:@jsr/std__testing@^1.0.19" ] } }, -- 2.51.2