Skip to content

fix: count the first rate-limited request and stop overlapping pg queries - #318

Merged
Musiker15 merged 1 commit into
mainfrom
fix/redis-ready-and-pg-query-overlap
Nov 20, 2026
Merged

Musiker15 merged 1 commit into
mainfrom
fix/redis-ready-and-pg-query-overlap

Conversation

@Musiker15

Copy link
Copy Markdown
Member

Description

Two warnings from the production logs.

Redis, "Stream isn't writeable and enableOfflineQueue options is false". getRedis() creates the client on the first rate-limited request. With enableOfflineQueue: false the first EVAL ran while the connection was still being set up, failed, and rateLimit let the request through without counting it. The web-error log shows exactly one of these after each of the last four restarts. rateLimit now waits up to 1 s for the initial connection through whenReady (lib/redis-ready.ts). It only waits for the first connect (wait, connecting, connect). While ioredis is reconnecting during an outage it does not wait, so the limiter still fails open immediately.

pg, "Calling client.query() when the client is already executing a query". In apps/realtime the LISTEN client looked up the guild for every notification without waiting for the previous lookup. pg 8 queues those queries and warns, pg 9 removes the queue. The lookups now go through createSerialQueue (apps/realtime/src/serial-queue.ts).

The warning that web and bot actually log has a different source: inside a transaction, @prisma/adapter-pg loads included relations with Promise.all on the same connection (prisma/orm#31112, prisma/orm#30925). 7.10.1 is the newest release, and the fix PRs (prisma/orm#30930, prisma/orm#29979) are still open. Results are correct under pg 8, so this PR only keeps pg 9 out: Dependabot now ignores pg majors, with a comment pointing at the issue. Remove that entry once Prisma ships the fix.

Type of change

  • Bugfix
  • New feature
  • Breaking change
  • Refactor / tech debt
  • Docs / CI

Checklist

  • pnpm lint, pnpm typecheck pass locally for web and realtime, realtime builds. The web build is left to CI.
  • Tests added: redis-ready.test.ts (web, 4 tests) and serial-queue.test.ts (realtime, 2 tests). Both fail with the fix taken out.
  • Prisma migration included (if the schema changed)
  • No secrets / .env values committed
  • Security implications considered: the rate limiter now counts the first request after a restart, and it still fails open while Redis is down.
  • Docs updated if architecture is affected

Linked issues

None in this repo. Upstream: prisma/orm#31112

…ries

The Redis client is created on the first rate-limited request. With
enableOfflineQueue off, that first EVAL ran before the connection was
ready, failed with "Stream isn't writeable", and the limiter let the
request through uncounted. On the server this showed up once after every
restart. rateLimit now waits up to 1 s for the initial connection. It
does not wait while ioredis reconnects during an outage, so that case
still fails open right away.

The realtime service looked up the guild for each notification on the
LISTEN client without waiting for the previous lookup to finish. pg 8
queues such queries and logs a deprecation warning, pg 9 drops the
queue. The lookups now run through a small serial queue.

Web and bot log the same pg warning, but there it comes from
@prisma/adapter-pg (prisma/orm#31112) and no fix has been released yet.
Dependabot skips pg majors until it is.
@graphify-labs

graphify-labs Bot commented Nov 20, 2026

Copy link
Copy Markdown

Graphify reviews are paused for this workspace because nobody has used it in 7 days. A workspace owner can resume reviews from the Repositories page: https://app.graphify.com/msk-scripts/repositories

@Musiker15
Musiker15 merged commit d0a2b35 into main Nov 20, 2026
4 checks passed
@Musiker15
Musiker15 deleted the fix/redis-ready-and-pg-query-overlap branch November 20, 2026 21:28
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