Higher timeout and log them as warning if any data was received

This might be the cause for  "number of retries reached 0" so
more specific logging calls might be useful. If while reading
a response it times out but  some data had already been read,
said data will be lost.

The sequence of events that triggered reaching 0 retries was:
- Sending requests with IDs XYZ
- socket.timeout while reading
- Items timed out. Retrying
- Processing RPC result
- Received response for XYZ
- Lost request with ID XYZ
This commit is contained in:
Lonami Exo 2018-03-18 20:01:19 +01:00
parent 35eccc0ba3
commit 987cf41ec6
2 changed files with 11 additions and 3 deletions

View File

@ -153,7 +153,6 @@ class TcpClient:
if self._socket is None:
self._raise_connection_reset(None)
# TODO Remove the timeout from this method, always use previous one
with BufferedWriter(BytesIO(), buffer_size=size) as buffer:
bytes_left = size
while bytes_left != 0:
@ -162,7 +161,16 @@ class TcpClient:
except socket.timeout as e:
# These are somewhat common if the server has nothing
# to send to us, so use a lower logging priority.
__log__.debug('socket.timeout "%s" while reading data', e)
if bytes_left < size:
__log__.warning(
'socket.timeout "%s" when %d/%d had been received',
e, size - bytes_left, size
)
else:
__log__.debug(
'socket.timeout "%s" while reading data', e
)
raise TimeoutError() from e
except ConnectionError as e:
__log__.info('ConnectionError "%s" while reading data', e)

View File

@ -170,7 +170,7 @@ class TelegramClient(TelegramBareClient):
use_ipv6=False,
proxy=None,
update_workers=None,
timeout=timedelta(seconds=5),
timeout=timedelta(seconds=10),
spawn_read_thread=True,
report_errors=True,
**kwargs):