Make confirm_received a flag, avoid race conditions, fix bg RPCError

There was a race condition between TelegramBareClient.invoke
receiving part and MtProtoSender._handle_rpc_result actually
reading the result after setting request.confirmed = True.

The .confirmed is now a threading.Event to avoid the sleep(0.1).

RPC errors have been moved inside the request so they're not
raised on a background thread anymore.
This commit is contained in:
Lonami Exo
2017-09-02 20:41:00 +02:00
parent b908296efa
commit 863d2e8368
3 changed files with 16 additions and 15 deletions

View File

@@ -294,8 +294,9 @@ class TelegramBareClient:
try:
self._sender.send(request)
while not request.confirm_received:
sleep(0.1) # TODO Use a proper lock
request.confirm_received.wait() # TODO Optional timeout here?
if request.rpc_error:
raise request.rpc_error
return request.result
except ConnectionResetError: