-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix Handling of Infinite Bootstrap Retries #4973
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Fixes infinite loop behavior when bootstrap_retries=-1 is set in Application.run_* and Updater.start_* methods by properly implementing retry termination conditions.
- Replaces
self.runningcondition with success tracking for webhook operations - Adds
is_runningparameter to application bootstrap initialization - Includes comprehensive tests for both polling and webhook scenarios
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/telegram/ext/_updater.py | Implements success tracking for webhook delete/set operations to prevent infinite retries |
| src/telegram/ext/_application.py | Adds proper termination condition for application initialization retries |
| tests/ext/test_updater.py | Adds test coverage for infinite bootstrap retries in updater methods |
| tests/ext/test_application.py | Adds test coverage for infinite bootstrap retries in application run methods |
| changes/unreleased/4973.PtSpAPsm7wh4PWc4p3uajX.toml | Documents the bugfix in changelog |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't looked at tests yet. while current approach solves the issue, i am wondering if there would be an issue when breaking the loop from within, i.e without the reliance on network_retry_loop.is_running to track success.
Changing this:
python-telegram-bot/src/telegram/ext/_utils/networkloop.py
Lines 120 to 125 in 6e951a9
| while effective_is_running(): | |
| try: | |
| await do_action() | |
| if not infinite_loop: | |
| _LOGGER.debug("%s Action succeeded. Stopping loop.", log_prefix) | |
| break |
to:
while effective_is_running():
try:
await do_action()
_LOGGER.debug("%s Action succeeded. Stopping loop.", log_prefix)
breakedit:
oh that might break polling i guess
yup :D Checking the return value would also basically bring us back to before #4880 😅 |
|
I am a bit late to those discussions :) but here goes I agree current approach is cleaner than the old However it's still way inferior to future me: i realize i say (long living action callback) a lot below. i mean an action callback that should be re-called even if first attempts are successful. That would be nicer, simpler than to assume every action callback is a long living one and require the caller to write custom logic in the form of lambdas to terminate the action. Now according to the discussion at comment #4880, i believe it was removed because it was thought redundant (
Yes it might not make sense passing Last note regarding #4871, i don't see an issue in incrementing retries count regardless of the success state of action_cb. Unless we want to support a use case like ('') and separate between retries because of errors, and normal operation (infinite_loop=True) retries. |
|
Let me re-add the |
When ready, Closes #4966
Will need to dig out my linux machine to write tests