-
Notifications
You must be signed in to change notification settings - Fork 453
fix: move email & sms send out of the POST /user
transaction
#2022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 15084496549Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies if you already considered this, but I think it's worth noting this is a really big behavior change and I worry without extensive tests there could be potential bugs or potential security considerations we are missing. I think it's worth thinking about what is done and rolled back in the current transaction.
For example the transaction in UserUpdate
will:
- UpdatePassword
- UpdateUserMetadata
- UpdateAppMetadata
- Conditionally:
- Call emailChangeVerify
- Calls ClearOneTimeTokenForUser
- Updates confirmation status
- Update identities and perform email confirmation
- Call emailChangeVerify
Knowing that I think it's worth evaluating what sendEmailChange
does and how it fails. For example it will call validateSentWithinFrequencyLimit
, have we carefully considered the consequences of leaving the transaction in UserUpdate
committed without performing all the write operations within sendEmailChange
.
@@ -263,5 +261,19 @@ func (a *API) UserUpdate(w http.ResponseWriter, r *http.Request) error { | |||
return err | |||
} | |||
|
|||
if sendEmailChange { | |||
// email sending should not hold a database transaction open as latency incurred by SMTP or HTTP hooks can exhaust the database pool | |||
if err := a.sendEmailChange(r, db, user, params.Email, flowType); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we thought through the consequences of not rolling back the previous values in the transaction when sendEmailChange fails at every failure point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think it should be fine. Yea the email send will fail, but the request will also fail and user can ask for re-send when email sending / SMS sending is back online.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to do the rate limit prior the transaction as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
278aa80
to
01c04ef
Compare
Keeping this inside the transaction can exhaust the database pool grinding full Auth to a halt, especially if the SMTP server or hook takes more than a few milliseconds to complete.