From fa267eef0320bc106ef1632fec789cfcf6183933 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Thu, 28 Mar 2024 18:59:21 +0300 Subject: [PATCH] fix: correctly reset session --- packages/bun/src/utils/tcp.ts | 2 +- packages/node/src/utils/tcp.ts | 2 +- packages/web/src/websocket.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bun/src/utils/tcp.ts b/packages/bun/src/utils/tcp.ts index dc0bd618..8ba8ac7e 100644 --- a/packages/bun/src/utils/tcp.ts +++ b/packages/bun/src/utils/tcp.ts @@ -79,12 +79,12 @@ export abstract class BaseTcpTransport extends EventEmitter implements ITelegram if (this._state === TransportState.Idle) return this.log.info('connection closed') - this.emit('close') this._state = TransportState.Idle this._socket?.end() this._socket = null this._currentDc = null this._packetCodec.reset() + this.emit('close') } handleError(socket: unknown, error: Error): void { diff --git a/packages/node/src/utils/tcp.ts b/packages/node/src/utils/tcp.ts index 4e925a5e..3fadbeb2 100644 --- a/packages/node/src/utils/tcp.ts +++ b/packages/node/src/utils/tcp.ts @@ -73,13 +73,13 @@ export abstract class BaseTcpTransport extends EventEmitter implements ITelegram if (this._state === TransportState.Idle) return this.log.info('connection closed') - this.emit('close') this._state = TransportState.Idle this._socket!.removeAllListeners() this._socket!.destroy() this._socket = null this._currentDc = null this._packetCodec.reset() + this.emit('close') } handleError(error: Error): void { diff --git a/packages/web/src/websocket.ts b/packages/web/src/websocket.ts index 4135ed8a..a612960e 100644 --- a/packages/web/src/websocket.ts +++ b/packages/web/src/websocket.ts @@ -130,13 +130,13 @@ export abstract class BaseWebSocketTransport extends EventEmitter implements ITe if (this._state === TransportState.Idle) return this.log.info('connection closed') - this.emit('close') this._state = TransportState.Idle this._socket!.removeEventListener('close', this.close) this._socket!.close() this._socket = null this._currentDc = null this._packetCodec.reset() + this.emit('close') } handleError(event: Event | { error: Error }): void {