mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-29 04:43:45 +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
|
# We need this to avoid using the updates thread if we're waiting to read
|
||||||
self.waiting_receive = False
|
self.waiting_receive = False
|
||||||
|
|
||||||
# Determine whether the received acknowledge request confirm
|
# Used when logging out, the only request that seems to use 'ack' requests
|
||||||
# our requests or not. This is not desired until we initialize
|
|
||||||
# our connection, because it breaks things when we call InvokeWithLayer
|
|
||||||
# TODO There might be a better way to handle msgs_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_interval = 60
|
||||||
self.ping_time_last = time()
|
self.ping_time_last = time()
|
||||||
|
@ -236,8 +234,8 @@ class MtProtoSender:
|
||||||
if request and request.msg_id in ack.msg_ids:
|
if request and request.msg_id in ack.msg_ids:
|
||||||
Log.w('Ack found for the current request ID')
|
Log.w('Ack found for the current request ID')
|
||||||
|
|
||||||
if self.ack_requests_confirm:
|
if self.logging_out:
|
||||||
Log.w('Message ack confirmed a request')
|
Log.i('Message ack confirmed the logout request')
|
||||||
request.confirm_received = True
|
request.confirm_received = True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -440,6 +438,16 @@ class MtProtoSender:
|
||||||
Log.d('Receiving updates timed out')
|
Log.d('Receiving updates timed out')
|
||||||
except ReadCancelledError:
|
except ReadCancelledError:
|
||||||
Log.i('Receiving updates cancelled')
|
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')
|
Log.d('Updates thread released the lock')
|
||||||
self.updates_thread_receiving = False
|
self.updates_thread_receiving = False
|
||||||
|
|
|
@ -259,18 +259,18 @@ class TelegramClient:
|
||||||
|
|
||||||
def log_out(self):
|
def log_out(self):
|
||||||
"""Logs out and deletes the current session. Returns True if everything went OK"""
|
"""Logs out and deletes the current session. Returns True if everything went OK"""
|
||||||
# Only the logout request is confirmed via an ack request
|
# Special flag when logging out (so the ack request confirms it)
|
||||||
# TODO This is only a supposition, there has to be a better way to handle acks
|
self.sender.logging_out = True
|
||||||
self.sender.ack_requests_confirm = True
|
|
||||||
try:
|
try:
|
||||||
self.invoke(LogOutRequest())
|
self.invoke(LogOutRequest())
|
||||||
|
self.disconnect()
|
||||||
if not self.session.delete():
|
if not self.session.delete():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.session = None
|
self.session = None
|
||||||
except:
|
except:
|
||||||
# Something happened when logging out, restore the state back
|
# Something happened when logging out, restore the state back
|
||||||
self.sender.ack_requests_confirm = False
|
self.sender.logging_out = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user