If terminate is called from an asyncio.CancelledError exception handler,
under an anyio task group, await will bail with asyncio.CancelledError
right away, leading to a connection leak.
Shielding the close() call allows the connection to be properly closed
in those cases.
try:
# try to gracefully close; see #10717
# timeout added in asyncpg 0.14.0 December 2017
- await_(self._connection.close(timeout=2))
+ await_(asyncio.shield(self._connection.close(timeout=2)))
except (
asyncio.TimeoutError,
asyncio.CancelledError,