Skip to content

Commit

Permalink
More reliable transport double-closing
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Aug 6, 2021
1 parent d718839 commit 337b779
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 0 additions & 7 deletions edgedb/asyncio_con.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ async def aclose(self):
try:
self._protocol.terminate()
await self._protocol.wait_for_disconnect()

# With asyncio on CPython 3.10 or lower, a normal exit
# (connection closed by peer) cannot set the transport._closed
# properly, leading to false ResourceWarning. Let's fix that by
# closing the transport again.
if not self._transport.is_closing():
self._transport.close()
except (Exception, asyncio.CancelledError):
self.terminate()
raise
Expand Down
6 changes: 6 additions & 0 deletions edgedb/protocol/asyncio_proto.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ cdef class AsyncIOProtocol(protocol.SansIOProtocol):
self.msg_waiter.set_exception(ConnectionResetError())
self.msg_waiter = None

# With asyncio sslproto on CPython 3.10 or lower, a normal exit
# (connection closed by peer) cannot set the transport._closed
# properly, leading to false ResourceWarning. Let's fix that by
# closing the transport again.
if not self.transport.is_closing():
self.transport.close()
self.transport = None

def pause_writing(self):
Expand Down

0 comments on commit 337b779

Please sign in to comment.