mealie-recipes / mealie

Mealie is a self hosted recipe manager and meal planner with a RestAPI backend and a reactive frontend application built in Vue for a pleasant user experience for the whole family. Easily add recipes into your database by providing the url and mealie will automatically import the relevant data or add a family recipe with the UI editor
https://docs.mealie.io
GNU Affero General Public License v3.0
7.26k stars 727 forks source link

[BUG] -Sending Test Email Results in Entire docker container freezing #4017

Closed SpawnInsane closed 1 week ago

SpawnInsane commented 2 months ago

First Check

What is the issue you are experiencing?

When sending a test email from the settings menu, test will fail after a few minutes. When trying to access mealie after test fails, results in unresponsive webpage when you try to refresh the page it will not refresh. when you try to access the URL again it will not load.

Have to restart docker container in order to use mealie again. Logs don't show anything since entire docker container freezes.

Steps to Reproduce

  1. Enter email address and send test email.
  2. Wait
  3. Test Fails and mealie becomes unresponsive

Please provide relevant logs

mealie.log

Mealie Version

Build Tag: c4a339ed36ad74cd4e6c7e22afc9c89c9dd4d8a2

Deployment

Unraid

Additional Deployment Details

No response

mechanarchy commented 2 months ago

I'm experiencing the same, exactly as described above. I have previously not had email configured, so can't provide any indication of when this may have broken. I am still on v1.9.0 but SpawnInsane is on v1.12.0 so it's not a recent regression.

Details Version: v1.9.0 Build: d96c36333b9cb9461c5dee96ae28b60d912b38fd Application Mode: Production Demo Status: Not Demo API Port: 9000 API Docs: Enabled Database Type: sqlite Recipe Scraper Version: 14.56.0

Checks Secure Site: Yes Server Side Base URL: Yes LDAP Ready: No OIDC Ready: Yes OpenAI Ready: No Email Configured: Yes

mechanarchy commented 2 months ago

Minimum reproducible example:

# Enter the container
docker exec -it mealie /bin/bash

# Open a Python REPL
cd /app/mealie
python3

# Run the following Python:
import smtplib
from mealie.core.config import get_app_settings
settings = get_app_settings()
server = smtplib.SMTP(settings.SMTP_HOST, settings.SMTP_PORT, timeout=3)

Result:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/smtplib.py", line 398, in getreply
    line = self.file.readline(_MAXLINE + 1)
  File "/usr/local/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.10/smtplib.py", line 343, in connect
    (code, msg) = self.getreply()
  File "/usr/local/lib/python3.10/smtplib.py", line 401, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed: "
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out

Here, obviously, it times out because I have specifically set timeout=3. But in the Mealie code, there is no timeout, so it blocks the thread indefinitely with no logging (hence the necessity to restart the container to resume service): https://github.com/mealie-recipes/mealie/blob/9acf9ec27c5595baed197c35900cd83f1375cdbd/mealie/services/email/email_senders.py#L64-L66

In my case, I am using this email configuration:

 'SMTP_AUTH_STRATEGY': 'TLS',
 'SMTP_FROM_EMAIL': 'redacted',
 'SMTP_FROM_NAME': 'Mealie',
 'SMTP_HOST': 'smtp.mailgun.org',
 'SMTP_PASSWORD': 'redacted',
 'SMTP_PORT': '465',
 'SMTP_USER': 'redacted',
mechanarchy commented 2 months ago

I just changed my port to 587 and it works now. I'm not sure what the root cause is but since I've achieved relief I don't really care. @SpawnInsane check your mail provider settings and see if an alternate port helps.

SpawnInsane commented 1 month ago

Realized I made a pretty stupid mistake when I initially configured all the settings for email. In the SMTP_HOST field I put smtp.google.com instead of the correct address smtp.gmail.com Emails now working.

flisk commented 2 weeks ago

Just stumbled over this issue because I ran into the same freezing behavior while setting up SMTP on my Mealie container. @SpawnInsane, would you mind re-opening it? I don't think it's sane behavior for Mealie to freeze completely while trying to send mail.