From 5849ce0e1b137dd25b872e5567f6ca09f55256e4 Mon Sep 17 00:00:00 2001 From: teidesu Date: Wed, 16 Jun 2021 18:21:17 +0300 Subject: [PATCH] fix(core): better handling for additional connections --- packages/core/src/base-client.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/core/src/base-client.ts b/packages/core/src/base-client.ts index 9016418a..9e5eeef6 100644 --- a/packages/core/src/base-client.ts +++ b/packages/core/src/base-client.ts @@ -450,13 +450,14 @@ export class BaseTelegramClient { if (this._useIpv6) { // first try to find ipv6 dc const found = this._config.dcOptions.find( - (it) => it.id === id && it.cdn === cdn && it.ipv6 + (it) => + it.id === id && it.cdn === cdn && it.ipv6 && !it.tcpoOnly ) if (found) return found } const found = this._config.dcOptions.find( - (it) => it.id === id && it.cdn === cdn + (it) => it.id === id && it.cdn === cdn && !it.tcpoOnly ) if (found) return found @@ -671,6 +672,19 @@ export class BaseTelegramClient { // connection.authKey was already generated at this point this.storage.setAuthKeyFor(dc.id, connection.authKey) await this._saveStorage() + } else { + // in case the auth key is invalid + const dcId = dc.id + connection.on('key-change', async (key) => { + // we don't need to export, it will be done by `.call()` + // in case this error is returned + // + // even worse, exporting here will lead to a race condition, + // and may result in redundant re-exports. + + this.storage.setAuthKeyFor(dcId, key) + await this._saveStorage() + }) } this._additionalConnections.push(connection)