mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-06 05:00:23 +03:00
Add a lock around connection.recv()
This commit is contained in:
parent
50515aa528
commit
d8376ee50d
|
@ -49,6 +49,7 @@ class MtProtoSender:
|
||||||
self.session = session
|
self.session = session
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
self._loop = loop if loop else asyncio.get_event_loop()
|
self._loop = loop if loop else asyncio.get_event_loop()
|
||||||
|
self._recv_lock = asyncio.Lock()
|
||||||
|
|
||||||
# Requests (as msg_id: Message) sent waiting to be received
|
# Requests (as msg_id: Message) sent waiting to be received
|
||||||
self._pending_receive = {}
|
self._pending_receive = {}
|
||||||
|
@ -123,7 +124,10 @@ class MtProtoSender:
|
||||||
Update and Updates objects.
|
Update and Updates objects.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
body = await self.connection.recv()
|
with await self._recv_lock:
|
||||||
|
# Receiving items is not an "atomic" operation since we
|
||||||
|
# need to read the length and then upcoming parts separated.
|
||||||
|
body = await self.connection.recv()
|
||||||
except (BufferError, InvalidChecksumError):
|
except (BufferError, InvalidChecksumError):
|
||||||
# TODO BufferError, we should spot the cause...
|
# TODO BufferError, we should spot the cause...
|
||||||
# "No more bytes left"; something wrong happened, clear
|
# "No more bytes left"; something wrong happened, clear
|
||||||
|
|
Loading…
Reference in New Issue
Block a user