fix(cache): log startup error when MemoryBackend is selected in production#223
Closed
anshul23102 wants to merge 1 commit into
Closed
fix(cache): log startup error when MemoryBackend is selected in production#223anshul23102 wants to merge 1 commit into
anshul23102 wants to merge 1 commit into
Conversation
…ction MemoryBackend is intentional for local development and tests, but in a serverless deployment (e.g. Vercel) each Lambda invocation gets its own isolated in-process store. Rate limits and any other feature that requires shared state across requests therefore have no effect when MemoryBackend is active. Previously, the fallback to MemoryBackend was completely silent. Operators had no indication from deployment logs that rate limiting was non-functional when neither KV_REST_API_URL+KV_REST_API_TOKEN (Upstash) nor REDIS_URL (self-hosted Redis) were configured. Changes: - pickDefaultBackend now emits a console.error startup message when it selects MemoryBackend and NODE_ENV === 'production', so the misconfiguration is immediately visible in Vercel function logs. - Adds __pickBackendName (test-only export) so the backend selection logic can be asserted in unit tests without reloading the module. - Adds six backend-selection tests to cache.test.ts covering all three backends, the Upstash-over-Redis priority, and the production warning. Closes Coder-s-OG-s#215
Contributor
|
@anshul23102 is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey @anshul23102 You have 5 open PRs right now. The limit is 3 at a time. Please get your existing PRs merged or closed before opening new ones:
This PR will remain open but won't be reviewed until you're under the limit. See our Contributing Guidelines for details. |
3 tasks
Author
3 tasks
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.
Summary
Fixes #215.
`pickDefaultBackend` silently fell back to `MemoryBackend` when neither `KV_REST_API_URL+KV_REST_API_TOKEN` (Upstash) nor `REDIS_URL` (self-hosted Redis) were set. In a serverless deployment (Vercel) each Lambda invocation is an isolated process with its own in-memory store, so `MemoryBackend` provides no cross-request state sharing. Rate limits, deduplication, and any other shared-state feature were silently non-functional in production without any log evidence.
Changes
`src/lib/cache.ts`
`src/lib/cache.test.ts`
Behaviour
UpstashBackend(no warning)REDIS_URLsetIoRedisBackend(no warning)development/testMemoryBackend(no warning, intended)productionMemoryBackend+console.errorstartup logTest plan
npx vitest run src/lib/cache.test.ts- 27/27 pass (21 existing + 6 new)npx tsc --noEmit- no errorsnpx eslint src/lib/cache.ts src/lib/cache.test.ts- no errors