use lock to handle 1 email at a time

This commit is contained in:
Son NK 2020-08-16 18:51:12 +02:00
parent d99d186bc0
commit a3a99ac3f4
1 changed files with 13 additions and 8 deletions

View File

@ -1226,15 +1226,20 @@ async def get_spam_score(message: Message) -> float:
class MailHandler:
lock = asyncio.Lock()
async def handle_DATA(self, server, session, envelope: Envelope):
try:
ret = await self._handle(envelope)
return ret
except Exception:
LOG.exception(
"email handling fail %s -> %s", envelope.mail_from, envelope.rcpt_tos
)
return "421 SL Retry later"
async with self.lock:
try:
ret = await self._handle(envelope)
return ret
except Exception:
LOG.exception(
"email handling fail %s -> %s",
envelope.mail_from,
envelope.rcpt_tos,
)
return "421 SL Retry later"
async def _handle(self, envelope: Envelope):
start = time.time()