Comments (4)
Hey thanks for the report!
We'll see if we can reproduce this
from aiosmtpd.
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.
hi all, i got same issue too. do anyone have fix on it?
from aiosmtpd.
@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)
- Replace flake8 test with ruff HOT 3
- Controller.start() is missing type annotation
- Provide a way to start smtp server on random free port
- [Question] EHLO response in a single packet?
- Example authenticated replayer is not working; Solved
- Let's put `aiosmtpd` under the `aio-libs` org on PyPI HOT 5
- [good first issue] Fix the Read The Docs config file HOT 1
- Some tests in aiosmtpd/tests/test_server.py hang with python 3.12
- assert_smtp_socket fails with Python 3.13.0a3 HOT 1
- custom `handle_HELO` and `handle_EHLO`: 503 Error: send HELO first HOT 1
- 1.4.5: test suite and documentation source is part of the installed resources HOT 2
- Not found code using 'attrs' but it is required. HOT 3
- handle_DATA not called with Proxy Protocol HOT 1
- Old authenticators won't work
- Unable to connect to aiosmtpd server using TLS v1.1 ?
- 1.4.6: pytest fails because test suite uses deprecated `pkg_resources
- 1.4.6: sphinx warnings `reference target not found`
- 1.4.6: please move aiosmtpd/docs and aiosmtpd/tests to project root, and pep517 build warnings
- examples/authenticated_relayer/server.py uses a random salt value
- _trigger_server in infinite loop
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiosmtpd.