Skip to content

Commit

Permalink
tests: Attempt to inhibit spurious ConnectionResetError on Windows (#…
Browse files Browse the repository at this point in the history
…1190)

The proactor stuff on Windows raises a spurious `ConnectionResetError`
while trying to shut down a socket in the `connection_lost` path.  This
is likely a Python bug (and nobody noticed because this is a background
exception).  Try to filter it out before complaining.
  • Loading branch information
elprans authored Oct 18, 2024
1 parent cee97e1 commit b732b4f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions asyncpg/_testbase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,22 @@ def setUp(self):
self.__unhandled_exceptions = []

def tearDown(self):
if self.__unhandled_exceptions:
excs = []
for exc in self.__unhandled_exceptions:
if isinstance(exc, ConnectionResetError):
texc = traceback.TracebackException.from_exception(
exc, lookup_lines=False)
if texc.stack[-1].name == "_call_connection_lost":
# On Windows calling socket.shutdown may raise
# ConnectionResetError, which happens in the
# finally block of _call_connection_lost.
continue
excs.append(exc)

if excs:
formatted = []

for i, context in enumerate(self.__unhandled_exceptions):
for i, context in enumerate(excs):
formatted.append(self._format_loop_exception(context, i + 1))

self.fail(
Expand Down

0 comments on commit b732b4f

Please sign in to comment.