Code Monkey home page Code Monkey logo

Comments (22)

apepenkov avatar apepenkov commented on May 14, 2024 2

I'm still not sure how exactly that race condition is happening, but I did remove some __del__ logic in 3.0 on the protocol that seems to have caused it to happen. Please try current main branch if you're able to. If it works, I'll put out a patch release.

can confirm, latest master version does not produce the error. win32, 3.11.6

from aiosmtplib.

polina-koval avatar polina-koval commented on May 14, 2024 2

The main branch works without errors 👍🏻

from aiosmtplib.

cole avatar cole commented on May 14, 2024 2

3.0.1 is out 🙂

from aiosmtplib.

cole avatar cole commented on May 14, 2024 1

I'm still not sure how exactly that race condition is happening, but I did remove some __del__ logic in 3.0 on the protocol that seems to have caused it to happen. Please try current main branch if you're able to. If it works, I'll put out a patch release.

from aiosmtplib.

polina-koval avatar polina-koval commented on May 14, 2024 1

I'm eagerly awaiting the patch. Thank you for your prompt responses and work :)

from aiosmtplib.

cole avatar cole commented on May 14, 2024

Last two lines meaning?

    print('success')
    #emulating work of other asyncio tasks...
    await asyncio.sleep(3)

from aiosmtplib.

Danstiv avatar Danstiv commented on May 14, 2024

Last two lines meaning?

    print('success')
    #emulating work of other asyncio tasks...
    await asyncio.sleep(3)

Because "Future exception was never retrieved" happens only if after calling quit passed at least a few seconds.

from aiosmtplib.

potens1 avatar potens1 commented on May 14, 2024

I get the same error with pytest test (using pytest-asyncio), for my tests it use gmail smtp with tls (if that matters)

setting PYTHONASYNCIODEBUG=1 this is the end of the output (everything before is not relevant)

...
File "/home/dev/development/newgateway/notifications_email_transport/src/notifications/transports/plugins/email/__init__.py", line 45, in send
    response = await aiosmtplib.send(
  File "/home/dev/.virtualenvs/notifications_email_transport-ELxUtyWv/lib/python3.8/site-packages/aiosmtplib/api.py", line 402, in send
    result = await client.sendmail(sender, recipients, message)
  File "/home/dev/.virtualenvs/notifications_email_transport-ELxUtyWv/lib/python3.8/site-packages/aiosmtplib/connection.py", line 151, in __aexit__
    await self.quit()
  File "/home/dev/.virtualenvs/notifications_email_transport-ELxUtyWv/lib/python3.8/site-packages/aiosmtplib/esmtp.py", line 236, in quit
    response = await self.execute_command(b"QUIT", timeout=timeout)
  File "/home/dev/.virtualenvs/notifications_email_transport-ELxUtyWv/lib/python3.8/site-packages/aiosmtplib/connection.py", line 420, in execute_command
    response = await self.protocol.execute_command(*args, timeout=timeout)
  File "/home/dev/.virtualenvs/notifications_email_transport-ELxUtyWv/lib/python3.8/site-packages/aiosmtplib/protocol.py", line 291, in execute_command
    response = await self.read_response(timeout=timeout)
  File "/home/dev/.virtualenvs/notifications_email_transport-ELxUtyWv/lib/python3.8/site-packages/aiosmtplib/protocol.py", line 268, in read_response
    self._response_waiter = self._loop.create_future()
  File "/usr/lib64/python3.8/asyncio/base_events.py", line 422, in create_future
    return futures.Future(loop=self)
aiosmtplib.errors.SMTPServerDisconnected: Unexpected EOF received

By the way, the mail is sent, even with the exception.

from aiosmtplib.

potens1 avatar potens1 commented on May 14, 2024

OK, trying to have a look at the problem, I just discovered this does not happen every time, I just ran my test bench twice in a row, (full stop start, not twice the same test in code), first time was without problem, the second one has the error... so it something not so easy to reproduce to test...

from aiosmtplib.

potens1 avatar potens1 commented on May 14, 2024

I'm not 100% sure but, it seems that it depends when the garbage collectors kick because, if I put some print statement in SMTPProtocol.__del__ it print after the warning. So it means the last response waiter created while doing the QUIT command is left until the end of the run for a very fast run because the __del__ is not called before the end (garbage collection not done yet). It means also that, while the warning is boring and not super clean, it should be harmless for normal operations (when the __del__ is called before the very end of the software).
Deleting the references and manually calling gc.collect at the end of tests, I'm not able anymore to get the warning (but... it does not prove anything since it was not 100% reproducible)

from aiosmtplib.

cole avatar cole commented on May 14, 2024

I'm kind of stuck on a fix for this, since this isn't very reproducible (depends on when garbage collection happens relative to loop shutdown).

Note though that the warning should be harmless.

from aiosmtplib.

SamyCookie avatar SamyCookie commented on May 14, 2024

Hi,

I reproduced this issue:

Future exception was never retrieved
future: <Future finished exception=SMTPServerDisconnected('Connection lost')>
aiosmtplib.errors.SMTPServerDisconnected: Connection lost

I think the issue is not in my code and indeed is random and must be related with garbage collection.

edit: I use version 1.1.6

from aiosmtplib.

suspiciousRaccoon avatar suspiciousRaccoon commented on May 14, 2024

I can reliably reproduce this issue with the following code based on the docs.

Python 3.11.2
Version 3.0.0

import asyncio
from email.message import EmailMessage

import aiosmtplib


async def send_hello_world():
    message = EmailMessage()
    message["From"] = "[email protected]"
    message["To"] = "[email protected]"
    message["Subject"] = "Hello World!"
    message.set_content("Sent via aiosmtplib")

    await aiosmtplib.send(
        message,
        hostname="smtp.gmail.com",
        port=587,
        username="[email protected]",
        password="used app password here"
    )
    print("Error happens after this print!")

asyncio.run(send_hello_world())

print("End of error!")

from aiosmtplib.

dokime7 avatar dokime7 commented on May 14, 2024

Same problem for me...

from aiosmtplib.

cole avatar cole commented on May 14, 2024

Oh nice, at least it's consistent on 3.11.2. Can you try the current main branch? I've made a change that fixes it for me.

from aiosmtplib.

suspiciousRaccoon avatar suspiciousRaccoon commented on May 14, 2024

I tried the new branch and the problem is still present with 3.11.2 on windows. Also tried with 3.10.12 on a linux VM and ran into the inconsistency problem, although it still happened.

However, I also found a way to avoid the problem:

import asyncio
from email.message import EmailMessage

import aiosmtplib


async def send_hello_world():
    message = EmailMessage()
    message["From"] = "[email protected]"
    message["To"] = "[email protected]"
    message["Subject"] = "Hello World!"
    message.set_content("Sent via aiosmtplib")

    await aiosmtplib.send(
        message,
        hostname="smtp.gmail.com",
        port=587,
        username="[email protected]",
        password="used app password here"
    )
    print("Error doesn't happens after this print!")

loop = asyncio.get_event_loop()
loop.run_until_complete(send_hello_world())

print("No error!")

I'm still very new to concurrency and the asyncio lib, so I'm not really sure why this works...?

from aiosmtplib.

Danstiv avatar Danstiv commented on May 14, 2024

Reproduced on 3.10, 3.11 and 3.12 with aiosmtplib 3.0.0.
In 3.12 some changes were made to the garbage collector, so it is strange that the problem appears in 3.11 and 3.10, perhaps changes were made to aiosmtplib itself.

from aiosmtplib.

apepenkov avatar apepenkov commented on May 14, 2024

I can confirm that I have that issue too. platform win32, python 3.11.6, aiosmtplib is 3.0.0

from aiosmtplib.

polina-koval avatar polina-koval commented on May 14, 2024

Reproduced on 3.10.9, with aiosmtplib 3.0.0. 😞

from aiosmtplib.

dokime7 avatar dokime7 commented on May 14, 2024

Unfortunately, sometimes the issue occurs again...

Future exception was never retrieved
future: <Future finished exception=SMTPServerDisconnected('Unexpected EOF received')>

python 3.11.6
aiosmtplib 3.0.1

from aiosmtplib.

cole avatar cole commented on May 14, 2024

@dokime7 any steps to reproduce?

from aiosmtplib.

dokime7 avatar dokime7 commented on May 14, 2024

No sorry, it's random...
I add that it's on Docker with image tiangolo/uvicorn-gunicorn:python3.11

from aiosmtplib.

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.