fix(gateway): isolate platform connect failures with per-platform timeout (#17242) - #17429
Merged
Conversation
…eout Wrap each adapter.connect() in asyncio.wait_for() so one platform hanging during startup or reconnect cannot block the others. Telegram's 8-retry connect loop (~140s worst case) previously prevented Feishu from ever starting when Telegram was network-restricted — common for users in regions where Telegram is blocked. Default timeout is 30s; override via HERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT (0 disables). Applied to both startup and the reconnect watcher so a platform that hangs mid-retry also does not stall retries for others. Fixes #17242
teknium1
force-pushed
the
hermes/hermes-bfbd0710
branch
from
April 29, 2026 12:00
188208f to
667d2e3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvage of #17270 by @tmimmanuel.
One platform's slow/hanging
adapter.connect()no longer blocks initialization of the others. Telegram's 8-retry connect loop (~140s worst case in network-restricted regions like China) previously prevented Feishu/Lark from ever starting when Telegram was unreachable — users had to comment Telegram out to get any other platform working.How
Wrap each
adapter.connect()call inasyncio.wait_for()via a new helper,_connect_adapter_with_timeout(). Used at both the startup loop and the reconnect watcher, so a platform that stalls mid-retry also does not stall retries for the others. On timeout the platform is queued for background reconnection like any other transient failure.HERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUTenv var0Changes
gateway/run.py: add_platform_connect_timeout_secs()+_connect_adapter_with_timeout(); route both startup and reconnect through it.tests/gateway/test_platform_reconnect.py: two new tests — one proving startup continues past a Telegram timeout and still connects Feishu, one proving the helper raises TimeoutError on hang.scripts/release.py: AUTHOR_MAP entry for tmimmanuel.Validation
scripts/run_tests.sh tests/gateway/test_platform_reconnect.py→ 16/16 passedHERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT=0.2→ bounded at 0.2s, raisesTimeoutErrorHERMES_GATEWAY_PLATFORM_CONNECT_TIMEOUT=0→ timeout disabled, connect runs unboundedSalvage notes
Cherry-picked tmimmanuel's
gateway/run.py+tests/gateway/test_platform_reconnect.pychanges onto current main. Dropped an unrelated cron/scheduler.py portion that was a rebase artifact from their earlier #17139 branch. Also closes #17383 by @vominh1919, which proposed the same timeout approach without tests and only on the startup path (missing the reconnect-watcher site).Closes #17242