debug session closing

This commit is contained in:
Jack Robison 2020-01-12 18:18:20 -05:00
parent 1a0d805bad
commit 8098438882
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 11 additions and 5 deletions

View file

@ -77,7 +77,7 @@ class ClientSession(BaseClientSession):
self.synchronous_close()
raise
except asyncio.CancelledError:
log.info("cancelled sending %s to %s:%i", method, *self.server)
log.warning("cancelled sending %s to %s:%i", method, *self.server)
self.synchronous_close()
raise
finally:
@ -102,7 +102,7 @@ class ClientSession(BaseClientSession):
except (asyncio.TimeoutError, OSError):
await self.close()
retry_delay = min(60, retry_delay * 2)
log.debug("Wallet server timeout (retry in %s seconds): %s:%d", retry_delay, *self.server)
log.warning("Wallet server timeout (retry in %s seconds): %s:%d", retry_delay, *self.server)
try:
await asyncio.wait_for(self.trigger_urgent_reconnect.wait(), timeout=retry_delay)
except asyncio.TimeoutError:
@ -127,7 +127,7 @@ class ClientSession(BaseClientSession):
controller.add(request.args)
def connection_lost(self, exc):
log.debug("Connection lost: %s:%d", *self.server)
log.warning("Connection lost: %s:%d", *self.server)
super().connection_lost(exc)
self.response_time = None
self.connection_latency = None
@ -223,7 +223,8 @@ class Network:
except asyncio.TimeoutError:
log.warning("Wallet server call timed out, retrying.")
except ConnectionError:
pass
log.warning("Ignoring connection error")
log.warning("Raising cancelled error")
raise asyncio.CancelledError() # if we got here, we are shutting down
def _update_remote_height(self, header_args):

View file

@ -131,6 +131,7 @@ class SessionBase(asyncio.Protocol):
self.transport.write(framed_message)
def _bump_errors(self):
self.logger.warning("bump errors %i", self.errors)
self.errors += 1
if self.errors >= self.max_errors:
# Don't await self.close() because that is self-cancelling
@ -181,6 +182,7 @@ class SessionBase(asyncio.Protocol):
"""Called by asyncio when the connection closes.
Tear down things done in connection_made."""
self.logger.error("connection lost to %s - %s", self.peer_address_str(), exc)
self._address = None
self.transport = None
self._task_group.cancel()
@ -220,12 +222,14 @@ class SessionBase(asyncio.Protocol):
def abort(self):
"""Forcefully close the connection."""
self.logger.warning("abort connection")
if self.transport:
self.transport.abort()
# TODO: replace with synchronous_close
async def close(self, *, force_after=30):
"""Close the connection and return when closed."""
self.logger.warning("close connection")
self._close()
if self._pm_task:
with suppress(CancelledError):
@ -234,6 +238,7 @@ class SessionBase(asyncio.Protocol):
await self._pm_task
def synchronous_close(self):
self.logger.warning("synchronous close")
self._close()
if self._pm_task and not self._pm_task.done():
self._pm_task.cancel()
@ -394,7 +399,7 @@ class RPCSession(SessionBase):
try:
requests = self.connection.receive_message(message)
except ProtocolError as e:
self.logger.debug(f'{e}')
self.logger.warning(f'protocol error {e}')
if e.error_message:
await self._send_message(e.error_message)
if e.code == JSONRPC.PARSE_ERROR: