Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,18 @@ export class InstanceController {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) waInstances?.clearCacheChatwoot();

if (instance.state === 'connecting' || instance.state === 'open') {
await this.logout({ instanceName });
try {
await this.logout({ instanceName });
} catch (logoutError) {
// RIGARR PATCH: zombie instance cleanup.
// When a Baileys socket is dead but waInstances[name] still exists,
// logout() throws "Connection Closed". Without this catch, the
// remove.instance emit below never runs, leaving the zombie in memory
// forever (only fixable by restarting the entire container).
this.logger.warn(
`[ZOMBIE-CLEANUP] logout failed for "${instanceName}" (likely zombie socket): ${logoutError?.toString?.() || logoutError}. Proceeding with cleanup.`,
);
}
}

try {
Expand Down