Fix reconnect sentinel when not reconnecting in send_loop

It would cause issues with the debug logs, since it assumes it's
a TLMessage, which have an .obj attribute. Second, the send_loop
is also smarter regarding reconnects (since OSError often occur
due to not being connected at all, namely ConnectionResetError).
This commit is contained in:
Lonami Exo 2018-06-20 18:19:35 +02:00
parent c8ee0bdca9
commit 4ab5c7d92d

View File

@ -338,8 +338,11 @@ class MTProtoSender:
self._pending_ack.clear()
messages = await self._send_queue.get()
if messages == _reconnect_sentinel and self._reconnecting:
if messages == _reconnect_sentinel:
if self._reconnecting:
break
else:
continue
if isinstance(messages, list):
message = self.state.create_message(MessageContainer(messages))
@ -364,11 +367,17 @@ class MTProtoSender:
continue
except asyncio.CancelledError:
return
except OSError as e:
except Exception as e:
if isinstance(e, ConnectionError):
__log__.info('Connection reset while sending %s', e)
elif isinstance(e, OSError):
__log__.warning('OSError while sending %s', e)
except:
__log__.exception('Unhandled exception while sending')
else:
__log__.exception('Unhandled exception while receiving')
await asyncio.sleep(1)
self._loop.create_task(self._reconnect())
break
else:
# Remove the cancelled messages from pending
__log__.info('Some futures were cancelled, aborted send')