From b4f731d8319a7bf4568c7886eeb9126cf81c0882 Mon Sep 17 00:00:00 2001 From: teidesu Date: Sun, 16 May 2021 12:49:51 +0300 Subject: [PATCH] feat(core): support rpc timeouts (for real) --- packages/core/src/network/telegram-connection.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/core/src/network/telegram-connection.ts b/packages/core/src/network/telegram-connection.ts index 8fd53c7e..59aeccfe 100644 --- a/packages/core/src/network/telegram-connection.ts +++ b/packages/core/src/network/telegram-connection.ts @@ -236,6 +236,7 @@ export class TelegramConnection extends PersistentConnection { private _resend(it: PendingMessage, id?: string): void { debug('resending %s', it.method) this._sendBufferForResult(it).catch(it.promise.reject) + if (it.cancel) clearTimeout(it.cancel) if (id) delete this._pendingRpcCalls[id] } @@ -613,6 +614,13 @@ export class TelegramConnection extends PersistentConnection { pending.cancel = setTimeout(() => { const pending = this._pendingRpcCalls[messageIdStr] if (pending) { + this.sendEncryptedMessage({ + _: 'mt_rpcDropAnswer', + reqMsgId: messageId, + }).catch(() => { + /* no-op */ + }) + const error = new RpcTimeoutError(timeout) if (this.params.niceStacks !== false) { makeNiceStack(error, pending.stack!, pending.method)