mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
The main race conditions, which actually happened in production was with concurrent execution of deliver_email and clear_scheduled_emails. clear_scheduled_emails could delete all email.users in the middle of deliver_email execution, causing it to pass empty to_user_ids list to send_email. We mitigate this by getting the list of user ids in a single query and moving forward with that snapshot, not having to worry about database data being mutated anymore. clear_scheduled_emails had potential race conditions with concurrent execution of itself due to not locking the appropriate rows upon selecting them for the purpose of potentially deleting them. FOR UPDATE locks need to be acquired to prevent simultaneous mutation. Tested manually with some print+sleep debugging to make some races happen. fixes #zulip-2k (sentry)
16 KiB
16 KiB