mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 10:53:44 +03:00
Fix updates thread crashing on logout
This commit is contained in:
parent
f6c34f8ba2
commit
6b2c0271ae
|
@ -30,11 +30,9 @@ class MtProtoSender:
|
|||
# We need this to avoid using the updates thread if we're waiting to read
|
||||
self.waiting_receive = False
|
||||
|
||||
# Determine whether the received acknowledge request confirm
|
||||
# our requests or not. This is not desired until we initialize
|
||||
# our connection, because it breaks things when we call InvokeWithLayer
|
||||
# Used when logging out, the only request that seems to use 'ack' requests
|
||||
# TODO There might be a better way to handle msgs_ack requests
|
||||
self.ack_requests_confirm = False
|
||||
self.logging_out = False
|
||||
|
||||
self.ping_interval = 60
|
||||
self.ping_time_last = time()
|
||||
|
@ -236,8 +234,8 @@ class MtProtoSender:
|
|||
if request and request.msg_id in ack.msg_ids:
|
||||
Log.w('Ack found for the current request ID')
|
||||
|
||||
if self.ack_requests_confirm:
|
||||
Log.w('Message ack confirmed a request')
|
||||
if self.logging_out:
|
||||
Log.i('Message ack confirmed the logout request')
|
||||
request.confirm_received = True
|
||||
|
||||
return False
|
||||
|
@ -440,6 +438,16 @@ class MtProtoSender:
|
|||
Log.d('Receiving updates timed out')
|
||||
except ReadCancelledError:
|
||||
Log.i('Receiving updates cancelled')
|
||||
except OSError as e:
|
||||
Log.w('OSError on updates thread, %s logging out',
|
||||
'was' if self.logging_out else 'was not')
|
||||
|
||||
if self.logging_out:
|
||||
# This error is okay when logging out, means we got disconnected
|
||||
# TODO Not sure why this happens because we call disconnect()…
|
||||
self.set_updates_thread(running=False)
|
||||
else:
|
||||
raise e
|
||||
|
||||
Log.d('Updates thread released the lock')
|
||||
self.updates_thread_receiving = False
|
||||
|
|
|
@ -259,18 +259,18 @@ class TelegramClient:
|
|||
|
||||
def log_out(self):
|
||||
"""Logs out and deletes the current session. Returns True if everything went OK"""
|
||||
# Only the logout request is confirmed via an ack request
|
||||
# TODO This is only a supposition, there has to be a better way to handle acks
|
||||
self.sender.ack_requests_confirm = True
|
||||
# Special flag when logging out (so the ack request confirms it)
|
||||
self.sender.logging_out = True
|
||||
try:
|
||||
self.invoke(LogOutRequest())
|
||||
self.disconnect()
|
||||
if not self.session.delete():
|
||||
return False
|
||||
|
||||
self.session = None
|
||||
except:
|
||||
# Something happened when logging out, restore the state back
|
||||
self.sender.ack_requests_confirm = False
|
||||
self.sender.logging_out = False
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue
Block a user