Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(session): count pending relaunches as orphans on infra import
Yudhi Armyndharis793be86383b9
diff --git a/src/modules/session/session.service.spec.ts b/src/modules/session/session.service.spec.tsindex f384b2e27..d50684f5b 100644--- a/src/modules/session/session.service.spec.ts+++ b/src/modules/session/session.service.spec.ts@@ -1070,6 +1070,15 @@ describe('SessionService', () => {expect(service.getActiveSessionIds()).toContain('sess-uuid-1');});+ it('counts a session waiting to relaunch after a failed reconnect as active for the import pre-flight', () => {+ // Its engine was evicted, but its timer re-registers one, so an import must see it as an orphan.+ const reconnectStates = (lifecycle as unknown as { reconnectStates: Map<string, ReconnectState> })+ .reconnectStates;+ reconnectStates.set('relaunching', { timer: null, attempts: 1, maxAttempts: 5, baseDelay: 1000 });++ expect(service.getActiveSessionIds()).toContain('relaunching');+ });+it('evicts and tears down the engine when engine.initialize() fails (no orphan wedging the session)', async () => {(repository.findOne as jest.Mock).mockResolvedValue(createMockSession());(repository.update as jest.Mock).mockResolvedValue({ affected: 1 });diff --git a/src/modules/session/session.service.ts b/src/modules/session/session.service.tsindex 7a048286e..ad0130820 100644--- a/src/modules/session/session.service.ts+++ b/src/modules/session/session.service.ts@@ -1146,11 +1146,12 @@ export class SessionService implements OnModuleDestroy, OnModuleInit, OnApplicat/*** Ids of every session with a live engine — including ones mid-initialization (their engine is not- * in `engines` yet but will register when start() completes). The infra import pre-flight uses this- * to refuse a full-replace restore that would orphan a running engine.+ * in `engines` yet but will register when start() completes) and ones waiting to relaunch after a+ * failed reconnect (their timer registers one). The infra import pre-flight uses this to refuse a+ * full-replace restore that would orphan a running engine.*/getActiveSessionIds(): string[] {- return this.engines.activeIds();+ return [...this.engineLifecycle.startSlotHolders()];}/** Whether this node has a MAX_CONCURRENT_SESSIONS slot free, counted exactly as the engine's cap check counts it. */