fix: delete instance cleanup on baileys failure#2508
Open
antonio-abrantes wants to merge 1 commit intoEvolutionAPI:developfrom
Open
fix: delete instance cleanup on baileys failure#2508antonio-abrantes wants to merge 1 commit intoEvolutionAPI:developfrom
antonio-abrantes wants to merge 1 commit intoEvolutionAPI:developfrom
Conversation
Contributor
There was a problem hiding this comment.
Sorry @antonio-abrantes, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
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
🐛 Problem
When calling
DELETE /instance/delete/{instanceName}on a corruptedinstance (disconnected/bugged Baileys session), the API returns:
{ "status": 400, "error": "Bad Request", "response": { "message": ["[object Object]"] } }After this error, the instance name remains permanently blocked in
waInstancesmemory. Even after manually cleaning the database, Redis,and session files, calling
POST /instance/createwith the same namereturns:
{ "status": 403, "message": ["This name \"agent-xxx\" is already in use."] }The only workaround was restarting the container — not viable in production environments.
🔍 Root Cause
Two bugs working together:
1. Aborted cleanup
deleteInstance()stopped execution iflogout()failed2. Bad error serialization
[object Object]✅ Fix
Split
try/catchinto isolated stepsEnsure cleanup always runs
Always remove instance from
waInstancesFix error serialization using:
🔗 Related Issue
Closes # (leave empty if not applicable)
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
N/A
✅ Checklist
📝 Additional Notes
Tested in production environment with Docker Swarm + PostgreSQL + Redis.
Fix only affects failure path — no impact on healthy instances.