Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in
U
upgrade-data-crawler-be
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • ThinhNC
  • upgrade-data-crawler-be
  • Merge Requests
  • !18

Merged
Opened Sep 09, 2026 by ThinhNC@ThinhNC
  • Report abuse
Report abuse

fix(redis): handle offline state in rate limiter and mount health routes under /api/v1

Summary of Changes

This PR fixes a critical unhandled Connection is closed error during authentication/API requests when Redis is offline or reconnected, and resolves 404 Not Found errors when accessing /api/v1/health/* endpoints through the Next.js BFF proxy.

Key Improvements

1. Rate Limiter Resilience & Fail-Open Behavior

  • Redis Readiness Guard: Updated createRateLimitStore in rate-limit.middleware.ts to check isRedisConnected(). If Redis is offline or not ready, it cleanly falls back to the in-memory MemoryStore.
  • Fail-Open Strategy: Added passOnStoreError: true to both rateLimitMiddleware and authRateLimiter. Any transient Redis hiccups or network drops will no longer throw an unhandled 500 error or block user logins.

2. Redis Connection Lifecycle

  • Connection Status Validation: Added exported isRedisConnected() helper in redis-client.ts to verify client.status === 'ready'.
  • Dead Instance Cleanup: Automatically reset generalClient = null when Redis connection transitions into 'end' or 'close' states, or when initial handshake fails during server startup.

3. Health Routes Mounting

  • BFF Proxy Compatibility: Mounted healthRoute under router.use("/health", healthRoute) in src/routes/index.ts, making /api/v1/health/readiness, /liveness, and /metrics accessible to the frontend proxy while preserving root-level /health for container orchestrators.

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b fix/redis-rate-limiter-and-health-routes origin/fix/redis-rate-limiter-and-health-routes

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/develop
git merge --no-ff fix/redis-rate-limiter-and-health-routes

Step 4. Push the result of the merge to GitLab

git push origin develop

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 0
  • Commits 1
  • Changes 49
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: ThinhNC/upgrade-data-crawler-be!18

Revert this merge request

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.