Giter Site home page Giter Site logo

Comments (4)

waynew avatar waynew commented on August 28, 2024

Hey thanks for the report!

We'll see if we can reproduce this

from aiosmtpd.

wevsty avatar wevsty commented on August 28, 2024

Hey thanks for the report!

We'll see if we can reproduce this

I have reproduced a similar problem.

Environment:
aiosmtpd 1.2
Ubuntu 18.04
Python 3.6.7

Test code is here:
server.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import asyncio
import time
import random
from aiosmtpd.controller import Controller


async def async_delay(second):
    await asyncio.sleep(second)


async def create_delay_task(loop):
    loop.create_task(
        async_delay(
            random.randint(1,1000)/1000
        )
    )
    await async_delay(random.randint(1,1000)/1000)


class CustomHandler:
    def __init__(self):
        pass

    async def handle_DATA(self, server, session, envelope):
        peer = session.peer
        mail_from = envelope.mail_from
        rcpt_tos = envelope.rcpt_tos
        mail_data = envelope.content
        # type: bytes
        # Process message data...
        try:
            return_message = '250 OK'
            loop = asyncio.get_event_loop()
            await create_delay_task(loop)
            await asyncio.sleep(1)
        except Exception as e:
            return_message = '500 Could not process your message'
        finally:
            return return_message


def start_aiosmtpd_proxy_server(host='127.0.0.1', port=10029):
    handler = CustomHandler()
    controller = Controller(handler, hostname=host, port=port, enable_SMTPUTF8=True)
    controller.start()
    while True:
        time.sleep(1000)
        pass
    controller.stop()


if __name__ == '__main__':
    start_aiosmtpd_proxy_server()
    pass

client.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time
import threading
import smtplib
from email.mime.text import MIMEText
from email.header import Header

def send_test_mail():
    sender = '[email protected]'
    receivers = ['[email protected]']
    message = MIMEText('Test mail.', 'plain', 'utf-8')
    message['From'] = Header("example_from", 'utf-8')
    message['To'] = Header("example_to", 'utf-8')

    subject = 'Python SMTP test.'
    message['Subject'] = Header(subject, 'utf-8')

    smtp_client = smtplib.SMTP()
    #smtp_client.set_debuglevel(True)
    try:
        smtp_client.connect(host='127.0.0.1', port=10029)
        smtp_client.ehlo("TEST")
        smtp_client.mail(sender)
        smtp_client.rcpt(receivers)
        smtp_client.sock.send(b'DATA\r\n')
        smtp_client.sock.send(message.as_string().encode())
        smtp_client.sock.send(b'\r\n.\r\n')
        smtp_client.sock.close()
    finally:
        pass
    pass


def main():
    while True:
        send_test_mail()
        time.sleep(0.1)
        # return
        pass
        

if __name__ == '__main__':
    main()
    pass

An error code will be displayed after running

Task exception was never retrieved
future: <Task finished coro=<SMTP._handle_client() done, defined at /usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py:236> exception=ConnectionResetError(104, 'Connection reset by peer')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 334, in _handle_client
    await self.push(status)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 224, in push
    await self._writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 329, in drain
    raise exc
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 326, in _handle_client
    await self.push(status)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 224, in push
    await self._writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 329, in drain
    raise exc
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 315, in _handle_client
    await method(arg)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 710, in smtp_DATA
    await self.push('250 OK' if status is MISSING else status)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 224, in push
    await self._writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 329, in drain
    raise exc
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 725, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
SMTP session exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 315, in _handle_client
    await method(arg)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 710, in smtp_DATA
    await self.push('250 OK' if status is MISSING else status)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 224, in push
    await self._writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 329, in drain
    raise exc
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 725, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
Exception in handle_exception()
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 326, in _handle_client
    await self.push(status)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 224, in push
    await self._writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 329, in drain
    raise exc
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 315, in _handle_client
    await method(arg)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 710, in smtp_DATA
    await self.push('250 OK' if status is MISSING else status)
  File "/usr/local/lib/python3.6/dist-packages/aiosmtpd/smtp.py", line 224, in push
    await self._writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 329, in drain
    raise exc
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 725, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

But The previous conclusion has a problem,The program did not stop working or generate an infinite loop, but it may cause the scheduling coroutine to slow down and eventually cause problems in my code.

from aiosmtpd.

kelvin5290 avatar kelvin5290 commented on August 28, 2024

hi all, i got same issue too. do anyone have fix on it?

from aiosmtpd.

wevsty avatar wevsty commented on August 28, 2024

@kelvin5290
I think it's probably the same as issues 127.
Maybe you could try using Python 3.8 or higher.
More see: #127

Since I've used other methods to avoid the problem, I'm not quite sure if the problem still exists at this point.
I'll find time in the next few days to try again.

from aiosmtpd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.