Skip to content
Permalink
Browse files

Don't send pings unless the connection is made

This will hopefully avoid batching tens of ping requests which
we don't care about their results.
  • Loading branch information
Lonami committed Dec 2, 2019
1 parent 149b26f commit cd37478e31b65ca2d993b69d2e39102ae63be324
Showing with 13 additions and 0 deletions.
  1. +6 −0 telethon/client/updates.py
  2. +7 −0 telethon/network/mtprotosender.py
@@ -335,6 +335,12 @@ def _process_update(self: 'TelegramClient', update, others, entities=None):
except Exception:
continue # Any disconnected exception should be ignored

# Don't bother sending pings until the low-level connection is
# ready, otherwise a lot of pings will be batched to be sent upon
# reconnect, when we really don't care about that.
if not self._sender._transport_connected():
continue

# We also don't really care about their result.
# Just send them periodically.
try:
@@ -128,6 +128,13 @@ def __init__(self, auth_key, loop, *, loggers,
def is_connected(self):
return self._user_connected

def _transport_connected(self):
return (
not self._reconnecting
and self._connection is not None
and self._connection._connected
)

async def disconnect(self):
"""
Cleanly disconnects the instance from the network, cancels

0 comments on commit cd37478

Please sign in to comment.
You can’t perform that action at this time.