Skip to content

Bot does not recover properly when using infinity_polling #1058

@ModischFabrications

Description

@ModischFabrications
  1. What version of pyTelegramBotAPI are you using? 3.7.4

  2. What OS are you using? Raspbian

  3. What version of python are you using? 3.6.9


Testing out bot.infinity_polling() as recommended in #1057 I noticed a bug in the recovery from exceptions:

It seems like the bot does not recover completely from a collision from another bot instance. It crashes and restarts successfully, which is nice, but it seems to get stuck in a restart loop every 3s (sleep time on recovery). I would guess there is an implicit state that carries over the restart that still contains the cancel instruction, but I haven't found anything obvious.

This bug can be bypassed by not starting another instance with the same token, but I assume that the same bug will also strike with other exceptions, unrelated to this cause.

Reproduction:

  1. Start instance 1 with bot.infinity_polling() and logging.INFO
  2. Start another instance to provoke a collision
  3. stop second bot to allow instance 1 to run
  4. -> instance 1 has crashed and is stuck in restart loop afterwards

log instance 1:

2020-12-31 16:03:07,705 (__init__.py:460 MainThread) INFO - TeleBot: "Started polling."
2020-12-31 16:19:07,961 (__init__.py:489 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 409. Description: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2020-12-31 16:19:07,961 (__init__.py:496 MainThread) INFO - TeleBot: "Waiting for 0.25 seconds until retry"
2020-12-31 16:19:11,546 (__init__.py:489 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 409. Description: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2020-12-31 16:19:11,546 (__init__.py:496 MainThread) INFO - TeleBot: "Waiting for 0.5 seconds until retry"
2020-12-31 16:42:57,901 (__init__.py:460 MainThread) INFO - TeleBot: "Started polling."
2020-12-31 16:43:00,905 (__init__.py:460 MainThread) INFO - TeleBot: "Started polling."
2020-12-31 16:43:03,908 (__init__.py:460 MainThread) INFO - TeleBot: "Started polling."
2020-12-31 16:43:06,914 (__init__.py:460 MainThread) INFO - TeleBot: "Started polling."
2020-12-31 16:43:09,920 (__init__.py:460 MainThread) INFO - TeleBot: "Started polling."

log instance 2:

2020-12-31 16:19:07,872 (__init__.py:460 MainThread) INFO - TeleBot: "Started polling."
2020-12-31 16:19:11,256 (__init__.py:489 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 409. Description: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2020-12-31 16:19:11,256 (__init__.py:496 MainThread) INFO - TeleBot: "Waiting for 0.25 seconds until retry"

Process finished with exit code -1

PS: Happy new year and thanks for the fast responses!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions