From 2b90f7db373fbc2c392d28cf65346bda3fcbcdb9 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 18 Oct 2025 20:59:13 +0000 Subject: [PATCH] filtermail: run CPU-intensive handle_DATA in a thread pool executor See for the documentation. This should avoid processing of large messages from hogging asyncio thread and delaying async operations like accepting new connections. --- CHANGELOG.md | 3 +++ chatmaild/src/chatmaild/filtermail.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b4c19d..7e662a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## untagged +- filtermail: run CPU-intensive handle_DATA in a thread pool executor + ([#676](https://github.com/chatmail/relay/pull/676)) + - don't use the complicated logging module in filtermail to exclude a potential source of errors. ([#674](https://github.com/chatmail/relay/pull/674)) diff --git a/chatmaild/src/chatmaild/filtermail.py b/chatmaild/src/chatmaild/filtermail.py index 8b0d133f..711f6585 100644 --- a/chatmaild/src/chatmaild/filtermail.py +++ b/chatmaild/src/chatmaild/filtermail.py @@ -241,6 +241,10 @@ class OutgoingBeforeQueueHandler: return "250 OK" async def handle_DATA(self, server, session, envelope): + loop = asyncio.get_running_loop() + return await loop.run_in_executor(None, self.sync_handle_DATA, envelope) + + def sync_handle_DATA(self, envelope): log_info("handle_DATA before-queue") error = self.check_DATA(envelope) if error: @@ -294,6 +298,10 @@ class IncomingBeforeQueueHandler: self.config = config async def handle_DATA(self, server, session, envelope): + loop = asyncio.get_running_loop() + return await loop.run_in_executor(None, self.sync_handle_DATA, envelope) + + def sync_handle_DATA(self, envelope): log_info("handle_DATA before-queue") error = self.check_DATA(envelope) if error: