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,10 +1,10 @@
- Stop the track-backfill proxies from spending the OpenSky credit budget the
main flights proxy is protecting. `/api/flights/track` and
`/api/military/track` now carry an always-on 30-per-minute per-client limiter
(90 global), and `/api/flights/track` honours the 429 cooldown that
`/api/flights` already sets: while the account is out of budget it serves any
cached track and otherwise answers `429` with the remaining cooldown rather
than spending 4 more credits. The existing 60-second per-key cache bounds
memory, not spend — a caller varying `icao24` produced a fresh upstream call
every time. Single-aircraft backfill, which is issued once per selected
contact, is unaffected (daikaginza, #685).
- Stop the track-backfill proxies from turning a varied `icao24`/`hex` into
unbounded upstream spend. `/api/flights/track` and `/api/military/track`
each carry an always-on 30-per-minute per-client limiter (90 global), and a
`429` from OpenSky `/tracks/all` now starts a cooldown for that credit
bucket: until OpenSky's retry-after passes, any cached track is served and
other lookups are answered `429` locally instead of asking for 4 more
credits. The `/tracks/*` bucket is separate from the `/states/*` one
`/api/flights` spends, so a flights cooldown does not block backfill. The
existing 60-second per-key cache bounds memory, not spend. Single-aircraft
backfill, issued once per selected contact, is unaffected (daikaginza, #685).