From 5f8fff5af3764b9a8ad3400e9b2a6d33f95718eb Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 16 Sep 2020 19:47:12 +0200 Subject: [PATCH] wrap shield around aiospamc.check to avoid the task being canceled --- email_handler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/email_handler.py b/email_handler.py index c1c06f0f..e60e5114 100644 --- a/email_handler.py +++ b/email_handler.py @@ -36,6 +36,7 @@ import email import os import time import uuid +from asyncio import shield from email import encoders from email.message import Message from email.mime.application import MIMEApplication @@ -1466,7 +1467,7 @@ async def get_spam_score(message: Message) -> float: try: # wait for at max 300s which is the default spamd timeout-child response = await asyncio.wait_for( - aiospamc.check(sa_input, host=SPAMASSASSIN_HOST), timeout=300 + shield(aiospamc.check(sa_input, host=SPAMASSASSIN_HOST)), timeout=300 ) return response.headers["Spam"].score except asyncio.TimeoutError: