Commit dcfb047a authored by Colomban Wendling's avatar Colomban Wendling

Mails: don't cache configuration values too early

As the user configuration is now loaded after the mails module, there
is a race in the mail thread that fetches configuration options, which
may or may not already have the user's value.

So, remove caching of those value, which leads for them to be read much
later after everything has properly been initialized.  The timeout
setting might still have the default value on the first loop run, but
this doesn't matter as the server isn't started at this point anyway.
parent 8a8842e1
......@@ -41,12 +41,11 @@ class ThreadedSMTP(object):
def __loop(self):
from . import config
host = config.emails.smtp_host
timeout = config.emails.smtp_keepalive_timeout
server = None
while self._loop or not self._queue.empty():
try:
timeout = config.emails.smtp_keepalive_timeout
args, kwargs = self._queue.get(timeout=timeout)
except queue.Empty:
server = self.__server_quit(server)
......@@ -54,7 +53,7 @@ class ThreadedSMTP(object):
if len(args) or len(kwargs): # ignore empty items
try:
if server is None:
server = smtplib.SMTP(host)
server = smtplib.SMTP(config.emails.smtp_host)
server.sendmail(*args, **kwargs)
except Exception as e:
logging.warning("Couldn't send email: %s" % str(e))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment