From 6d59b9d63a3adbeff16345ed629c4e746baef5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 28 Oct 2024 18:11:58 +0200 Subject: [PATCH] Fix _FakeServer to immediately close client connections 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: #394 --- aiosmtpd/controller.py | 3 +++ aiosmtpd/tests/test_server.py | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/aiosmtpd/controller.py b/aiosmtpd/controller.py index fbb16be8..ef6ed296 100644 --- a/aiosmtpd/controller.py +++ b/aiosmtpd/controller.py @@ -108,6 +108,9 @@ def _cb_client_connected( ) -> None: pass + def connection_made(self, transport): + transport.close() + @public class BaseController(metaclass=ABCMeta): diff --git a/aiosmtpd/tests/test_server.py b/aiosmtpd/tests/test_server.py index 443c0833..45ffe02c 100644 --- a/aiosmtpd/tests/test_server.py +++ b/aiosmtpd/tests/test_server.py @@ -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):