telegraf: Should handle 429 flood wait errors during polling
Context
- Telegraf.js Version: 4.4.2
- Node.js Version: 17.1.0
- Operating System: alpine
Minimal Example Code Reproducing the Issue
const { Telegraf } = require('telegraf');
const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN);
bot.start((ctx) => ctx.reply('Welcome'));
bot.on('text', async (ctx) => { ...
Not sure how to reproduce the issue, but here is a stack trace
2021-12-30T15:32:31.446352795Z /usr/src/app/node_modules/telegraf/lib/core/network/client.js:263
2021-12-30T15:32:31.446436840Z throw new error_1.default(data, { method, payload });
2021-12-30T15:32:31.446457232Z ^
2021-12-30T15:32:31.446472689Z
2021-12-30T15:32:31.446487615Z TelegramError: 429: Too Many Requests: retry after 5
2021-12-30T15:32:31.446502487Z at Telegram.callApi (/usr/src/app/node_modules/telegraf/lib/core/network/client.js:263:19)
2021-12-30T15:32:31.446517557Z at runMicrotasks (<anonymous>)
2021-12-30T15:32:31.446532914Z at processTicksAndRejections (node:internal/process/task_queues:96:5)
2021-12-30T15:32:31.446548317Z at async Polling.[Symbol.asyncIterator] (/usr/src/app/node_modules/telegraf/lib/core/network/polling.js:27:33)
2021-12-30T15:32:31.446563300Z at async Polling.loop (/usr/src/app/node_modules/telegraf/lib/core/network/polling.js:69:30) {
2021-12-30T15:32:31.446578644Z response: {
2021-12-30T15:32:31.446592851Z ok: false,
2021-12-30T15:32:31.446607299Z error_code: 429,
2021-12-30T15:32:31.446621857Z description: 'Too Many Requests: retry after 5',
2021-12-30T15:32:31.446667056Z parameters: { retry_after: 5 }
2021-12-30T15:32:31.446685253Z },
2021-12-30T15:32:31.446699808Z on: {
2021-12-30T15:32:31.446714119Z method: 'getUpdates',
2021-12-30T15:32:31.446728450Z payload: { timeout: 50, offset: 462581445, allowed_updates: [] }
2021-12-30T15:32:31.446743346Z }
2021-12-30T15:32:31.446757413Z }
Expected Behavior
I assume that polling should swallow this 429 and silently continue working after this response from Telegram
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16
Commits related to this issue
- Retry `getUpdates` upon 429; fixes #1563 — committed to PabloWenger/telegraf by wojpawlik 2 years ago
Apparently the method
getUpdatesis only specified to never return 429 errors during normal operation of the Bot API server. However, it can indeed return 429 when the Bot API server is closing.Consequently, telegraf should be changed to handle flood wait errors during long polling by checking the error status code for containing 429, and delaying subsequent calls to
getUpdatesby the specified number of seconds.This error is explicitly specified not to happen. Telegraf already handles all possible errors correctly. It doesn’t make sense to deviate from their specification. I forwarded this issue to Telegram.
It’s not a good first issue to work on for any new contributors because this cannot be solved easily. In fact, this might not be possible at all to be solved on our end. It requires some level of understanding about how the Bot API server works, and how it communicates with Telegram via MTProto.
Check this I recommend you use https://npm.im/telegraf-throttler