mirror of
https://github.com/chatmail/relay.git
synced 2026-05-17 03:48:58 +00:00
filtermail: run CPU-intensive handle_DATA in a thread pool executor
See <https://docs.python.org/3/library/asyncio-eventloop.html#executing-code-in-thread-or-process-pools> for the documentation. This should avoid processing of large messages from hogging asyncio thread and delaying async operations like accepting new connections.
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## untagged
|
## 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.
|
- don't use the complicated logging module in filtermail to exclude a potential source of errors.
|
||||||
([#674](https://github.com/chatmail/relay/pull/674))
|
([#674](https://github.com/chatmail/relay/pull/674))
|
||||||
|
|
||||||
|
|||||||
@@ -241,6 +241,10 @@ class OutgoingBeforeQueueHandler:
|
|||||||
return "250 OK"
|
return "250 OK"
|
||||||
|
|
||||||
async def handle_DATA(self, server, session, envelope):
|
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")
|
log_info("handle_DATA before-queue")
|
||||||
error = self.check_DATA(envelope)
|
error = self.check_DATA(envelope)
|
||||||
if error:
|
if error:
|
||||||
@@ -294,6 +298,10 @@ class IncomingBeforeQueueHandler:
|
|||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
async def handle_DATA(self, server, session, envelope):
|
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")
|
log_info("handle_DATA before-queue")
|
||||||
error = self.check_DATA(envelope)
|
error = self.check_DATA(envelope)
|
||||||
if error:
|
if error:
|
||||||
|
|||||||
Reference in New Issue
Block a user