Repository navigation
fix: count the first rate-limited request and stop overlapping pg queries - #318
Merged
Merged
Conversation
…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 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. WithenableOfflineQueue: falsethe firstEVALran while the connection was still being set up, failed, andrateLimitlet the request through without counting it. The web-error log shows exactly one of these after each of the last four restarts.rateLimitnow waits up to 1 s for the initial connection throughwhenReady(lib/redis-ready.ts). It only waits for the first connect (wait,connecting,connect). While ioredis isreconnectingduring 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/realtimethe 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 throughcreateSerialQueue(apps/realtime/src/serial-queue.ts).The warning that web and bot actually log has a different source: inside a transaction,
@prisma/adapter-pgloadsincluded relations withPromise.allon 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 ignorespgmajors, with a comment pointing at the issue. Remove that entry once Prisma ships the fix.Type of change
Checklist
pnpm lint,pnpm typecheckpass locally forwebandrealtime,realtimebuilds. The web build is left to CI.redis-ready.test.ts(web, 4 tests) andserial-queue.test.ts(realtime, 2 tests). Both fail with the fix taken out..envvalues committedLinked issues
None in this repo. Upstream: prisma/orm#31112