From 65375e48360fd9cff652afdd7cb106b26f02755a Mon Sep 17 00:00:00 2001 From: devlikepro Date: Mon, 12 Aug 2024 14:05:40 +0700 Subject: [PATCH] [core] wait until, so we don't close a websocket on connecting --- src/core/engines/noweb/session.noweb.core.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index 6726c7f9..8a78a23a 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -46,6 +46,7 @@ import { PollVotePayload, WAMessageAckBody, } from '@waha/structures/webhooks.dto'; +import { waitUntil } from '@waha/utils/promiseTimeout'; import { SingleDelayedJobRunner } from '@waha/utils/SingleDelayedJobRunner'; import { SinglePeriodicJobRunner } from '@waha/utils/SinglePeriodicJobRunner'; import * as Buffer from 'buffer'; @@ -444,6 +445,9 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { this.sock?.ev?.removeAllListeners(); this.sock?.ws?.removeAllListeners(); await this.store?.close(); + // wait until connection is not connecting to avoid error: + // "WebSocket was closed before the connection was established" + await waitUntil(async () => !this.sock?.ws?.isConnecting, 1_000, 10_000); this.sock?.end(undefined); }