/** * ALB ↔ Node HTTP keep-alive contract. * * An ALB holds idle keep-alive connections to its targets open for up to its * idle timeout and freely reuses them. Node's default `server.keepAliveTimeout` * is 5 seconds — far below the ALB's 60 — so the ALB routinely reuses a * connection at the instant Node closes it, surfacing as intermittent * ALB-generated 502s that never reach the application. The fix is server-side: * the target's keep-alive timeout must exceed the ALB idle timeout, and * `headersTimeout` must exceed `keepAliveTimeout` so a request that starts * arriving just before the keep-alive deadline is not truncated mid-headers. * * The Fjall ECS construct pins the ALB idle timeout to * `DEFAULT_ALB_IDLE_TIMEOUT_SECONDS` and injects that value into ALB-fronted * containers as `FJALL_ALB_IDLE_TIMEOUT_SECONDS` (see * `components/infrastructure/lib/resources/aws/compute/applicationLoadBalancer.ts`). * This module is the consuming half of the contract: call * `applyAlbKeepAliveTimeouts(server)` after `listen()`. When the env var is * absent (local dev, containers deployed before the construct injected it) the * AWS default of 60 seconds is assumed, which yields the same timeouts. */ export declare const FJALL_ALB_IDLE_TIMEOUT_ENV_VAR = "FJALL_ALB_IDLE_TIMEOUT_SECONDS"; /** * The ALB idle timeout every Fjall ALB is pinned to (also the AWS default, * assumed when the env var is absent). The construct imports this constant so * the ALB attribute, the injected env var, and this fallback cannot drift. */ export declare const DEFAULT_ALB_IDLE_TIMEOUT_SECONDS = 60; export interface AlbKeepAliveTimeouts { albIdleTimeoutSeconds: number; keepAliveTimeoutMs: number; headersTimeoutMs: number; } /** Structural subset of `node:http.Server` this module tunes. */ export interface KeepAliveTunableServer { keepAliveTimeout: number; headersTimeout: number; } /** * Resolves the keep-alive timeouts for a server behind a Fjall ALB from * `FJALL_ALB_IDLE_TIMEOUT_SECONDS`. Throws on a malformed value — a * misconfigured contract must fail the boot loudly, not race the ALB. */ export declare function resolveAlbKeepAliveTimeouts(env?: Record): AlbKeepAliveTimeouts; /** * Applies the resolved timeouts to a Node HTTP(S) server and returns them so * the caller can log what was applied. */ export declare function applyAlbKeepAliveTimeouts(server: KeepAliveTunableServer, env?: Record): AlbKeepAliveTimeouts;