fix: gracefully disconnect Telegram client on exit
Without calling `client.disconnect()`, the TCP connection to Telegram's servers is abandoned when the process exits. If the server restarts quickly (common with MCP stdio servers), Telegram sees two connections using the same auth key simultaneously and permanently revokes it with `AuthKeyDuplicatedError`, requiring the user to regenerate their session. Add a `finally` block to `_main()` so `client.disconnect()` is always called on exit, allowing Telegram's servers to clean up the connection state promptly.
This commit is contained in:
parent
a050889fc8
commit
53589ba836
1 changed files with 5 additions and 0 deletions
5
main.py
5
main.py
|
|
@ -4776,6 +4776,11 @@ async def _main() -> None:
|
|||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
finally:
|
||||
try:
|
||||
await client.disconnect()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def main() -> None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue