Skip to content

Commit

Permalink
Fix _FakeServer to immediately close client connections
Browse files Browse the repository at this point in the history
Without this, if the SMTP server throws an exception during
initialization, Controller.stop() gets stuck indefinitely waiting
on active connections.

Note: this only happens in Python 3.12+. Earlier versions of Python
allowed `wait_closed()` to complete regardless of active connections.

With this change the TestFactory testcases can again be enabled for
Python 3.12+.

Fixes: aio-libs#394
  • Loading branch information
cuu508 committed Oct 28, 2024
1 parent 9ecdc36 commit 6d59b9d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 3 additions & 0 deletions aiosmtpd/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def _cb_client_connected(
) -> None:
pass

def connection_made(self, transport):
transport.close()


@public
class BaseController(metaclass=ABCMeta):
Expand Down
1 change: 0 additions & 1 deletion aiosmtpd/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ def test_inet_contstop(self, temp_event_loop, runner):
assert temp_event_loop.is_closed() is False


@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Hangs on 3.12")
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
class TestFactory:
def test_normal_situation(self):
Expand Down

0 comments on commit 6d59b9d

Please sign in to comment.