Ensure that the connection object is connected and valid
(self, connection: AbstractConnection)
| 1628 | return self.connection_class(**self.connection_kwargs) |
| 1629 | |
| 1630 | async def ensure_connection(self, connection: AbstractConnection): |
| 1631 | """Ensure that the connection object is connected and valid""" |
| 1632 | await connection.connect() |
| 1633 | # connections that the pool provides should be ready to send |
| 1634 | # a command. if not, the connection was either returned to the |
| 1635 | # pool before all data has been read or the socket has been |
| 1636 | # closed. either way, reconnect and verify everything is good. |
| 1637 | try: |
| 1638 | if await connection.can_read(): |
| 1639 | raise ConnectionError("Connection has data") from None |
| 1640 | except (ConnectionError, TimeoutError, OSError): |
| 1641 | await connection.disconnect() |
| 1642 | await connection.connect() |
| 1643 | if await connection.can_read(): |
| 1644 | raise ConnectionError("Connection not ready") from None |
| 1645 | |
| 1646 | async def release(self, connection: AbstractConnection): |
| 1647 | """Releases the connection back to the pool""" |
no test coverage detected