Skip to content

fix(session): reduce session maxAge from 365 to 90 days - #1365

Open
itsalaidbacklife wants to merge 1 commit into
mainfrom
fix/session-maxage-90-days
Open

fix(session): reduce session maxAge from 365 to 90 days#1365
itsalaidbacklife wants to merge 1 commit into
mainfrom
fix/session-maxage-90-days

Conversation

@itsalaidbacklife

Copy link
Copy Markdown
Contributor

Problem

Production users could log in (the flow appeared to succeed and landed them on HomeView), but their sessions were never persisted — the game-list request errored and a refresh booted them back to login.

Server logs showed the root cause was the Redis session store, not the app:

error: Error occurred in session middleware :: "ReplyError: OOM command not allowed when used memory > 'maxmemory'."

The production Redis add-on (Heroku Mini plan, 25 MB, maxmemory-policy: noeviction) had filled up. Under noeviction, Redis rejects every write once full — so authenticated sessions were never written, and the login response had already been sent (hence the accompanying Cannot write to response more than once / response headers have already been sent warnings).

Why it filled up

connect-redis@6.1.3 derives each session key's Redis TTL from the cookie's expires/maxAge (_getTTL in lib/connect-redis.js). With cookie.maxAge set to 365 days, every session key lived ~1 year and accumulated on a 25 MB store until it wedged.

Change

Reduce cookie.maxAge from 365 → 90 days in config/session.js. Because connect-redis couples the Redis key TTL to maxAge, new session keys now expire in ~90 days (refreshed on activity via touch), so memory turns over naturally. Active users are unaffected; only genuinely idle sessions expire.

Operational fixes already applied out-of-band

  • Flushed the wedged Redis (FLUSHALL) to restore login immediately.
  • Set the add-on eviction policy to allkeys-lru as a safety net so a full store evicts LRU sessions instead of rejecting all writes.

This PR is the durable code-side complement to those.

Follow-ups (not in this PR)

  • Consider bumping the Redis plan for more headroom.
  • Rotate the hard-coded session secret in config/session.js to an env var (pre-existing; out of scope for this outage fix).

🤖 Generated with Claude Code

The production Redis session store (Mini plan, 25MB) was hitting
maxmemory and rejecting all writes with "OOM command not allowed",
which silently broke login (sessions never persisted). connect-redis
derives each session key's Redis TTL from the cookie's maxAge, so the
365-day maxAge meant session keys lived ~1 year and accumulated until
the store filled. Reducing maxAge to 90 days lets memory turn over
naturally. Paired with an allkeys-lru eviction policy on the add-on.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@itsalaidbacklife itsalaidbacklife added version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1) backend Requires changes to the (node) backend webserver labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Requires changes to the (node) backend webserver version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant