From 36abe3defd6ca3cc8f9eb6b8f04b9ab860ff58e8 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Tue, 17 Dec 2024 08:42:49 +0300 Subject: [PATCH] fix(core): reconnection fixes --- packages/core/src/network/persistent-connection.ts | 9 +++++++-- packages/core/src/network/session-connection.ts | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/core/src/network/persistent-connection.ts b/packages/core/src/network/persistent-connection.ts index 9ef89309..d7f0a6ab 100644 --- a/packages/core/src/network/persistent-connection.ts +++ b/packages/core/src/network/persistent-connection.ts @@ -37,8 +37,7 @@ export abstract class PersistentConnection { // inactivity timeout private _inactivityTimeout: timers.Timer | null = null - private _inactive = true - + _inactive = true _destroyed = false _usable = false @@ -169,6 +168,11 @@ export abstract class PersistentConnection { } reconnect(): void { + if (this._disconnectedManually) { + this._disconnectedManually = false + this.connect() + return + } this._fuman.reconnect(true) } @@ -176,6 +180,7 @@ export abstract class PersistentConnection { if (this._inactivityTimeout) { timers.clearTimeout(this._inactivityTimeout) } + this._disconnectedManually = true await this._fuman.close() } diff --git a/packages/core/src/network/session-connection.ts b/packages/core/src/network/session-connection.ts index ff1a7729..20be9903 100644 --- a/packages/core/src/network/session-connection.ts +++ b/packages/core/src/network/session-connection.ts @@ -237,7 +237,7 @@ export class SessionConnection extends PersistentConnection { if (this._usePfs) { if (!this._isPfsBindingPending && this._session._authKeyTemp.ready) { - this.log.info('transport error 404, reauthorizing pfs') + this.log.debug('transport error 404, reauthorizing pfs') // this is important! we must reset temp auth key before // we proceed with new temp key derivation. @@ -253,7 +253,7 @@ export class SessionConnection extends PersistentConnection { return } else if (this._isPfsBindingPending) { - this.log.info('transport error 404, pfs binding in progress') + this.log.debug('transport error 404, pfs binding in progress') this._onAllFailed('temp key expired, binding pending') @@ -264,11 +264,10 @@ export class SessionConnection extends PersistentConnection { } // there happened a little trolling - this.log.info('transport error 404, reauthorizing') + this.log.warn('transport error 404, reauthorizing') this._session.resetAuthKey() this._resetSession() this.onKeyChange.emit(null) - this.onError.emit(error) return } @@ -1488,6 +1487,7 @@ export class SessionConnection extends PersistentConnection { this._online = online if (online) { + if (this._inactive) return this.reconnect() } else { this.disconnectManual().catch((err) => {