Skip to content

Race condition in Dispatcher.start/stop() #881

@subdir

Description

@subdir

Steps to reproduce

Run slighly modified example from https://python-telegram-bot.org/

from telegram.ext import Updater, CommandHandler

def start(bot, update):
    update.message.reply_text('Hello World!')

def hello(bot, update):
    update.message.reply_text(
        'Hello {}'.format(update.message.from_user.first_name))

updater = Updater('YOUR TOKEN HERE')

updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CommandHandler('hello', hello))

updater.start_polling()
try:
    # this call to non-existing function may cause dispatcher.stop() to be called
    # before dispatcher.start() had time to set self.running=True,
    # thus stop() does nothing and dispatcher continues to run.
    CALL_TO_NON_EXISTING_FUNC()
finally:
    updater.stop()

Expected behaviour

Application should stop

Actual behaviour

Application continues to run and does not reacting to CTRL+C

Configuration

Operating System:
Linux

Version of Python, python-telegram-bot & dependencies:

$ python -m telegram
python-telegram-bot 8.1.1
certifi 2017.07.27.1
future 0.15.2
Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]

Logs

Insert logs here (if necessary)
Not necessary

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions