Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updater.py: Better handling of timeouts during getUpdates #1007

Merged
merged 2 commits into from Feb 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions telegram/ext/updater.py
Expand Up @@ -30,7 +30,7 @@

from telegram import Bot, TelegramError
from telegram.ext import Dispatcher, JobQueue
from telegram.error import Unauthorized, InvalidToken, RetryAfter
from telegram.error import Unauthorized, InvalidToken, RetryAfter, TimedOut
from telegram.utils.helpers import get_signal_name
from telegram.utils.request import Request
from telegram.utils.webhookhandler import (WebhookServer, WebhookHandler)
Expand Down Expand Up @@ -267,11 +267,9 @@ def start_webhook(self,

def _start_polling(self, poll_interval, timeout, read_latency, bootstrap_retries, clean,
allowed_updates): # pragma: no cover
# """
# Thread target of thread 'updater'. Runs in background, pulls
# updates from Telegram and inserts them in the update queue of the
# Dispatcher.
# """

cur_interval = poll_interval
self.logger.debug('Updater thread started')
Expand All @@ -288,8 +286,12 @@ def _start_polling(self, poll_interval, timeout, read_latency, bootstrap_retries
except RetryAfter as e:
self.logger.info(str(e))
cur_interval = 0.5 + e.retry_after
except TimedOut as toe:
self.logger.debug('Timed out getting Updates: %s', toe)
# If get_updates() failed due to timeout, we should retry asap.
cur_interval = 0
except TelegramError as te:
self.logger.error("Error while getting Updates: {0}".format(te))
self.logger.error('Error while getting Updates: %s', te)

# Put the error into the update queue and let the Dispatcher
# broadcast it
Expand All @@ -310,7 +312,8 @@ def _start_polling(self, poll_interval, timeout, read_latency, bootstrap_retries

cur_interval = poll_interval

sleep(cur_interval)
if cur_interval:
sleep(cur_interval)

@staticmethod
def _increase_poll_interval(current_interval):
Expand Down