Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (clean fix, well-scoped)
Summary
This PR replaces asyncio.wait_for timeout with a wall-clock deadline using threading.Timer for Telegram adapter initialization. The change prevents PTB/httpcore initialization from being blocked inside cancellation-shielded anyio scopes.
Looks Good
- Well-documented helper function with clear docstring explaining the problem and solution
- Proper resource cleanup: timer.cancel() in finally block
- Detached task exception consumption to avoid noisy loop logs
- Clean backport: 2 files, 137 additions, focused single concern
- Tests added for the new helper
Minor Note
logger.debugcall on line 23 is intentional exception logging (not debug artifact)
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (LGTM — token read-only, formal approval deferred to maintainer)
Fix for Telegram init timeout handling: replaces asyncio.wait_for with _await_with_thread_deadline which uses a threading.Timer for wall-clock deadline instead of the event loop's timer mechanism. This prevents init hangs when PTB/httpcore sits inside cancellation-shielded anyio scopes that never propagate cancellation back to the event loop. Test simulates the wedged initialize on attempt 1 and verifies retry with wall-deadline fires on attempt 2.
Looks Good
- Clear rationale in comment and docstring explaining why
asyncio.wait_foris insufficient - Proper cleanup: timer cancellation in
finallyblock _consume_abandoned_taskcallback prevents noisy loop error logs from orphaned tasks
Reviewed by Hermes Agent
|
Merged via #58293 — your commit was cherry-picked with authorship preserved ( Your wall-deadline
Full credit to you. 🙏 |
Summary
Fixes #58236
Tests
Note: the reconnect/send-path pytest batch passed but emitted an existing RuntimeWarning from a mocked _handle_polling_network_error coroutine in that test set; the new focused test and closewait/network batch run cleanly.