Skip to content

feat: WithMaxSessions to bound the live session map#113

Merged
joaomdsg merged 1 commit into
mainfrom
feat/max-sessions
Jun 10, 2026
Merged

feat: WithMaxSessions to bound the live session map#113
joaomdsg merged 1 commit into
mainfrom
feat/max-sessions

Conversation

@joaomdsg

Copy link
Copy Markdown
Member

Critic panel finding #10 (minor; perf + security). The session map had no cap — asymmetric with the existing WithMaxContexts — so a cookieless crawler could mint unbounded sessions and OOM the pod.

Change

WithMaxSessions(n): once the cap is met, a request that would mint or adopt a new session is rejected with 503. A client that already holds a live session is never refused. The cap check is fused with the map insert under sessionsMu (TOCTOU-safe, mirroring tryRegisterCtx). Default 0 = no cap.

Tests

  • rejects beyond cap (cookieless flood → 503)
  • zero disables the cap
  • returning client (cookie jar) reuses its session at cap=1, never 503
  • negative value panics at registration

Full ci-check.sh green.

A cookieless crawler could mint unbounded sessions and OOM the pod — the
session map had no cap, asymmetric with the existing WithMaxContexts.

Add WithMaxSessions(n): once the cap is met, a request that would mint or
adopt a NEW session is rejected with 503 (the cap check is fused with the map
insert under sessionsMu, so concurrent mints can't both slip past). A client
that already holds a live session is never refused. Default 0 (no cap).
@joaomdsg
joaomdsg merged commit cc1f1ef into main Jun 10, 2026
4 checks passed
@joaomdsg
joaomdsg deleted the feat/max-sessions branch June 10, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant