You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug report & fix for Evolution API WAMonitoringService — stream:error 515 kills healthy instances #2498
In v2.2.3, when a user scans a QR code to connect WhatsApp, the connection is immediately killed ~7
seconds later by WAMonitoringService even though WhatsApp connected successfully.
Exact sequence (from Docker logs):
stream:error code=515 ← WhatsApp sends "Connection Replaced" (normal multi-device
protocol)
Baileys reconnects ← Baileys handles it correctly, reconnects in ~5s
CONNECTED TO WHATSAPP ✓ ← Session is open, webhook fires state='open'
WAMonitoringService: REMOVED ← 7 seconds later, Evolution API kills it
WAMonitoringService: LOGOUT ← Instance gone
Root cause (in src/whatsapp/services/whatsapp.baileys.service.ts):
When stream:error 515 fires, WAMonitoringService starts a removal timer. Baileys recovers and fires
connection.update state='open' — but the timer is never cancelled. After Baileys reconnects,
WhatsApp sends 401 loggedOut to clean up the old session slot. Evolution API's close handler sees
401 → triggers logout.instance → REMOVED.
The 401 after a 515 is normal WhatsApp multi-device behavior — it's not a real logout. But Evolution
API treats it as one.
The fix:
In the connection close handler (whatsapp.baileys.service.ts), track when a 515 just occurred and
treat any 401 that fires within a 30-second window as a reconnect, not a logout:
// Somewhere on the class:
private _lastStream515At = 0;
// In the stream error handler:
if (node.tag === 'stream:error' && node.attrs.code === '515') {
this._lastStream515At = Date.now();
}
// In the connection.update close handler (the existing condition):
// BEFORE:
const shouldReconnect = ![
DisconnectReason.loggedOut,
DisconnectReason.forbidden,
402,
406,
].includes(statusCode);
Activity
fix(baileys): prevent healthy instances from being killed after strea…
dpaes commentedon Apr 24, 2026
the latest version its 2.3.7, please check if u can reproduce in the latest @OmarEltak
fix(baileys): prevent healthy instances from being killed after strea…
fix(baileys): prevent healthy instances from being killed after strea…
fix(baileys): prevent healthy instances from being killed after strea…