This repository was archived by the owner on Jun 16, 2026. It is now read-only.
fix(auth): prevent caching of failed backend instances in getStorageBackend#9237
Open
Sandeep6135 wants to merge 3 commits into
Open
Conversation
Contributor
|
@Sandeep6135 is attempting to deploy a commit to the sandeepvashishtha's projects Team on Vercel. A member of the Team first needs to authorize it. |
b5ef3d1 to
2253be4
Compare
2253be4 to
e4681a3
Compare
There was a problem hiding this comment.
Gates Failed
New code is healthy
(4 new files with code health below 10.00)
Enforce advisory code health rules
(4 files with Complex Method, Complex Conditional, Overall Code Complexity)
Our agent can fix these. Install it.
Gates Passed
2 Quality Gates Passed
Reason for failure
| New code is healthy | Violations | Code Health Impact | |
|---|---|---|---|
| signup.js | 2 rules | 8.67 | Suppress |
| _user-storage.js | 1 rule | 9.18 | Suppress |
| reauth.js | 2 rules | 9.39 | Suppress |
| login.js | 1 rule | 9.53 | Suppress |
| Enforce advisory code health rules | Violations | Code Health Impact | |
|---|---|---|---|
| signup.js | 2 advisory rules | 8.67 | Suppress |
| _user-storage.js | 1 advisory rule | 9.18 | Suppress |
| reauth.js | 2 advisory rules | 9.39 | Suppress |
| login.js | 1 advisory rule | 9.53 | Suppress |
Quality Gate Profile: Clean Code Collective
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Pull Request: Prevent Caching of Failed Storage Backend Instances
🚨 Severity & Classification
Closes BUG: Permanently Cached Failed Instance in User Storage Factory (High) #8998
📝 Problem Summary
In the user storage abstraction factory (
api/auth/_user-storage.js), thegetStorageBackendfunction was assigning the instantiated class instance to the global/module-scopedstorageBackendvariable before executing the asynchronous.initialize()call:If initialization fails (e.g. database network drops, invalid configuration, connection timeout), the exception is thrown, but the failed, uninitialized instance remains cached in
storageBackend.On all subsequent requests,
getStorageBackend()checksif (storageBackend) { return storageBackend; }and immediately returns the broken instance without attempting to re-initialize or retry connection. This causes the entire application authentication layer to remain permanently broken even after the database recovers.🛠️ Solution Overview
1. Safe Initialization Pattern (Delayed Assignment)
Refactored
getStorageBackend()inapi/auth/_user-storage.jsto instantiate and initialize the backend within a local variable. The globalstorageBackendvariable is only assigned after the asynchronous initialization completes successfully:If
.initialize()fails, the globalstorageBackendremainsnull. Next calls will trigger a fresh initialization attempt, allowing the application to self-heal and reconnect.2. Base Class Exports & Imports Cleanup
StorageBackendfromapi/auth/_user-storage.jsso it can be verified in unit tests.src/__tests__/user-storage.test.jsto point to_user-storage.js(with an underscore) instead of the public route path, complying with Vercel's internal file convention.3. Factory Caching Integrity Test Case
Added a test case
should not cache failed storage backend instance on initialization failuretosrc/__tests__/user-storage.test.js:🧪 Verification Results
All 22 unit tests for the user-storage abstraction pass successfully:
Test Files: 1 passed | Tests: 22 passed | Duration: ~4.5s