fix(instance): handle stale DB records after restart + prevent Redis connection spam#3
Merged
eksucampusmarketplace-cell merged 1 commit intoMay 4, 2026
Conversation
…spam - Instance guard: when creating an instance, detect if the name exists in the database but not in memory (stale after server restart). Auto cleanup the stale DB record so re-creation succeeds instead of returning 403 'name already in use' followed by 404 on all operations. - Redis client: skip connection when CACHE_REDIS_ENABLED is false or CACHE_REDIS_URI is empty. Previously the client would attempt to connect regardless, flooding logs with 'redis disconnected' errors every second when no Redis server is available. - .env.example: change defaults to CACHE_REDIS_ENABLED=false and CACHE_LOCAL_ENABLED=true so deployments without Redis work out of the box (Dockerfile copies .env.example as .env). Co-Authored-By: Chris Tolu <eksucampusmarketplace@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Fixes two critical issues that affect deployments on PaaS platforms (Render, Railway, etc.) where the server restarts frequently:
1. Stale Instance Deadlock After Restart
When Evolution API restarts, the in-memory
waInstancesmap is cleared but database records persist. This creates a deadlock:Fix: The
instanceLoggedGuardnow detects when an instance exists in the database but NOT in memory (stale after restart). Instead of returning 403, it auto-cleans the stale DB record viacleaningStoreData()and allows re-creation.2. Redis Connection Spam When Disabled
The Redis client (
rediscache.client.ts) would attempt to connect regardless ofCACHE_REDIS_ENABLEDsetting. Since the Dockerfile copies.env.exampleas.env(which hadCACHE_REDIS_ENABLED=true), deployments without Redis got flooded with "redis disconnected" errors every second.Fix:
ENABLEDflag and URI before attempting connection.env.exampledefaults changed toCACHE_REDIS_ENABLED=falseandCACHE_LOCAL_ENABLED=trueso deployments without Redis work out of the box🔗 Related Issue
Fixes instance creation failures and Redis spam on PaaS deployments (Render free tier).
🧪 Type of Change
🧪 Testing
npm run buildpassesnpm run lint:checkpassesFiles Changed
src/api/guards/instance.guard.ts— Added stale instance detection and cleanupsrc/cache/rediscache.client.ts— Added ENABLED/URI checks before connecting.env.example— Changed Redis default to false, local cache to true✅ Checklist
📝 Additional Notes
This is the third in a series of PaaS deployment fixes:
DATABASE_URL→DATABASE_CONNECTION_URImappingLink to Devin session: https://app.devin.ai/sessions/812442be799c4cd59ca9c40eee75263b
Requested by: @eksucampusmarketplace-cell