alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
630 stars 113 forks source link

RPC.handleDecryptedMessage read properties of undefined #251

Open korzhyk opened 2 years ago

korzhyk commented 2 years ago

Describe the bug https://github.com/alik0211/mtproto-core/blob/0dec9b0f490035214c3479da2fd7eced624ff7c7/src/rpc/index.js#L552 TypeError: Cannot read properties of undefined (reading 'resolve')

/src/app/node_modules/@mtproto/core/src/rpc/index.js:552

        waitMessage.resolve(message.result);
                    ^

TypeError: Cannot read properties of undefined (reading 'resolve')
    at RPC.handleDecryptedMessage (/src/app/node_modules/@mtproto/core/src/rpc/index.js:552:21)
    at /src/app/node_modules/@mtproto/core/src/rpc/index.js:473:14
    at Array.forEach (<anonymous>)
    at RPC.handleDecryptedMessage (/src/app/node_modules/@mtproto/core/src/rpc/index.js:472:24)
    at RPC.handleEncryptedMessage (/src/app/node_modules/@mtproto/core/src/rpc/index.js:451:10)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Code example I have just one listener for updates

mtproto.updates.on('updates', (updateInfo) => {
  console.log('updates:', updateInfo);
});

Expected behavior Promise resolve

Context:

VityaSchel commented 2 years ago

I have the same problem. Looking at logs, it may be an issue with telegram ratelimiting. I was banned for 291 seconds, and on ~60 library crashed. I suppose it doing the same request every second and then telegram decides to just shutoff this connection (which is not documented and not supported by library). Or it was logs from my previous crashes. Who knows :)

VityaSchel commented 2 years ago

Anyway, the best solution I see is to schedule a restart every day or try to catch this exact type of error. I disabled autorestarting on error because I'm too afraid of running into looping error => ratelimit ban. My bot has been working like that, restarting everyday, for a month or so and I only noticed this error when checking logs, it didn't affect the bot's actions