Skip to content

Commit 109e8ab

Browse files
authored
fix(telegram): add explicit read_timeout for get_updates polling (#173)
On macOS, when the machine sleeps and wakes up (e.g. closing and reopening a MacBook), the existing long-polling connection can become stale. PTB may then reuse this dead connection from its pool, and without an explicit client-side read_timeout it can hang indefinitely, leaving the bot completely unresponsive. Set an explicit HTTPXRequest(read_timeout=30) for get_updates so that hanging connections are capped at 30s before being discarded and retried.
1 parent 2ed867b commit 109e8ab

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/bub/channels/telegram.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from telegram import Bot, Message, Update
1313
from telegram.ext import Application, CommandHandler, ContextTypes, filters
1414
from telegram.ext import MessageHandler as TelegramMessageHandler
15+
from telegram.request import HTTPXRequest
1516

1617
from bub.channels.base import Channel
1718
from bub.channels.message import ChannelMessage, MediaItem, MediaType
@@ -169,7 +170,8 @@ async def start(self, stop_event: asyncio.Event) -> None:
169170
len(self._allow_chats),
170171
bool(proxy),
171172
)
172-
builder = Application.builder().token(self._settings.token)
173+
get_updates_request = HTTPXRequest(read_timeout=30)
174+
builder = Application.builder().token(self._settings.token).get_updates_request(get_updates_request)
173175
if proxy:
174176
builder = builder.proxy(proxy).get_updates_proxy(proxy)
175177
self._app = builder.build()

0 commit comments

Comments
 (0)