fix(server): give /tracks its own credit cooldown, armed by its own 429

The branch read the /states/all cooldown from /api/flights and never set
one from /tracks/all, which is backwards for an API that meters the two
separately: a flights cooldown blocked backfill that still had credits,
and a /tracks 429 left every other icao24 free to ask again.

tracks.js now keeps a cooldown for the /tracks bucket, armed by a 429
from /tracks/all with OpenSky's retry-after (opensky.js exports its
existing parser so both buckets read the header the same way). The two
routes get separate limiters, and a limiter refusal sends Retry-After 60,
the window, rather than 10.
This commit is contained in:
daikaginza committed 2026-10-23 12:34:46 +07:00
1 parent a073e6e658
commit bfcf12af49
4 files changed
+67 -55

No files matched your search

+1 -1
View File
@@ -5276,7 +5276,7 @@ pins and share links already supply complete boxes.
- `/api/military-installations` uses an independent limiter with the same 90-per-client/300-global one-minute bounds, so viewport installation refreshes never consume `/api/overpass` annotation capacity.
- `/api/route` proxies bounded OSRM route requests for annotation routes, with profile allowlisting, distance caps, response caps, caching, and sanitized "no route found" errors.
- Track endpoints: `/api/vessels/track?mmsi=` (server-accumulated ring buffers; sub-route handled before the rows snapshot), `/api/flights/track?icao24=` (OAuth, 60s cache, sanitized errors, independent OpenSky credit bucket), `/api/military/track?hex=` (60s cache, 5MB cap, ODbL attribution required in UI).
- Both track-backfill routes carry an always-on per-client limiter of 30 requests/minute (90 global), because their 60s per-key cache bounds memory rather than spend: a caller varying `icao24`/`hex` produces a fresh key and a fresh upstream call each time. `/api/flights/track` additionally reads `/api/flights`'s 429 credit cooldown and, while it is active, serves any cached track and otherwise answers `429` with the remaining cooldown instead of spending 4 more credits against an account that is already out of budget.
- Each track-backfill route carries its own always-on per-client limiter of 30 requests/minute (90 global; refusals send `Retry-After: 60`), because their 60s per-key cache bounds memory rather than spend: a caller varying `icao24`/`hex` produces a fresh key and a fresh upstream call each time. A `429` from OpenSky `/tracks/all` starts a cooldown for the `/tracks/*` credit bucket (OpenSky's retry-after, bounded 30 s–30 min): while it runs, `/api/flights/track` serves any cached track and otherwise answers `429` with the remaining cooldown instead of spending 4 more credits. It does not read `/api/flights`'s `/states/*` cooldown, since OpenSky meters the two buckets independently.
- Realtime debug logs redact API keys, bearer tokens, client secrets, and image data URLs before writing to disk; request bodies are size-capped.
- `/api/realtime/debug-log` enforces an always-on 120-per-client/400-global one-minute limiter (not the opt-in `GEV_RATELIMIT_OPENAI_PER_MIN` bucket the cost-bearing OpenAI routes share), appends asynchronously through a serialized queue, and rotates `realtime-conversations.jsonl` at 32 MB keeping one prior generation, so the sink is bounded at twice that regardless of session length. A malformed record answers 400 and a failed write 500, both with a fixed message.