Skip to content

Commit

Permalink
Convert sending mail to async/await. (matrix-org#7557)
Browse files Browse the repository at this point in the history
Mainly because sometimes the email push code raises exceptions where the
stack traces have gotten lost, which is hopefully fixed by this.
  • Loading branch information
erikjohnston authored and phil-flex committed Jun 16, 2020
1 parent cf800ef commit 1e211f1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/7557.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert sending mail to async/await.
9 changes: 4 additions & 5 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ def try_unbind_threepid_with_id_server(self, mxid, threepid, id_server):

return changed

@defer.inlineCallbacks
def send_threepid_validation(
async def send_threepid_validation(
self,
email_address,
client_secret,
Expand Down Expand Up @@ -319,7 +318,7 @@ def send_threepid_validation(
"""
# Check that this email/client_secret/send_attempt combo is new or
# greater than what we've seen previously
session = yield self.store.get_threepid_validation_session(
session = await self.store.get_threepid_validation_session(
"email", client_secret, address=email_address, validated=False
)

Expand Down Expand Up @@ -353,7 +352,7 @@ def send_threepid_validation(
# Send the mail with the link containing the token, client_secret
# and session_id
try:
yield send_email_func(email_address, token, client_secret, session_id)
await send_email_func(email_address, token, client_secret, session_id)
except Exception:
logger.exception(
"Error sending threepid validation email to %s", email_address
Expand All @@ -364,7 +363,7 @@ def send_threepid_validation(
self.hs.clock.time_msec() + self.hs.config.email_validation_token_lifetime
)

yield self.store.start_or_continue_validation_session(
await self.store.start_or_continue_validation_session(
"email",
email_address,
session_id,
Expand Down
4 changes: 2 additions & 2 deletions tests/rest/client/v2_alpha/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def make_homeserver(self, reactor, clock):
# Email config.
self.email_attempts = []

def sendmail(smtphost, from_addr, to_addrs, msg, **kwargs):
async def sendmail(smtphost, from_addr, to_addrs, msg, **kwargs):
self.email_attempts.append(msg)
return

Expand Down Expand Up @@ -358,7 +358,7 @@ def make_homeserver(self, reactor, clock):
# Email config.
self.email_attempts = []

def sendmail(smtphost, from_addr, to_addrs, msg, **kwargs):
async def sendmail(smtphost, from_addr, to_addrs, msg, **kwargs):
self.email_attempts.append(msg)

config["email"] = {
Expand Down

0 comments on commit 1e211f1

Please sign in to comment.