forked from LBRYCommunity/lbry-sdk
close connection and reraise on CancelledError
This commit is contained in:
parent
7b0e4617d3
commit
07bae26fd3
2 changed files with 9 additions and 3 deletions
|
@ -80,9 +80,9 @@ class ClientSession(BaseClientSession):
|
||||||
await asyncio.wait_for(self.trigger_urgent_reconnect.wait(), timeout=retry_delay)
|
await asyncio.wait_for(self.trigger_urgent_reconnect.wait(), timeout=retry_delay)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
pass
|
pass
|
||||||
except asyncio.CancelledError as exception:
|
except asyncio.CancelledError:
|
||||||
self.connection_lost(exception)
|
self.synchronous_close()
|
||||||
raise exception
|
raise
|
||||||
finally:
|
finally:
|
||||||
self.trigger_urgent_reconnect.clear()
|
self.trigger_urgent_reconnect.clear()
|
||||||
|
|
||||||
|
|
|
@ -254,6 +254,7 @@ class SessionBase(asyncio.Protocol):
|
||||||
if self.transport:
|
if self.transport:
|
||||||
self.transport.abort()
|
self.transport.abort()
|
||||||
|
|
||||||
|
# TODO: replace with synchronous_close
|
||||||
async def close(self, *, force_after=30):
|
async def close(self, *, force_after=30):
|
||||||
"""Close the connection and return when closed."""
|
"""Close the connection and return when closed."""
|
||||||
self._close()
|
self._close()
|
||||||
|
@ -263,6 +264,11 @@ class SessionBase(asyncio.Protocol):
|
||||||
self.abort()
|
self.abort()
|
||||||
await self._pm_task
|
await self._pm_task
|
||||||
|
|
||||||
|
def synchronous_close(self):
|
||||||
|
self._close()
|
||||||
|
if self._pm_task and not self._pm_task.done():
|
||||||
|
self._pm_task.cancel()
|
||||||
|
|
||||||
|
|
||||||
class MessageSession(SessionBase):
|
class MessageSession(SessionBase):
|
||||||
"""Session class for protocols where messages are not tied to responses,
|
"""Session class for protocols where messages are not tied to responses,
|
||||||
|
|
Loading…
Reference in a new issue