mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 12:21:58 +00:00
submessage: Select Message FOR UPDATE when creating.
This locks the message while creating a submessage, which will handle race conditions caused by deleting the message simultaneously. We make sure that events work happens outside the transaction, so that in case there's a problem with the queue processor, the locks aren't held for too long.
This commit is contained in:
committed by
Tim Abbott
parent
5f4113cf60
commit
efc2f49e3c
@@ -2141,6 +2141,10 @@ def do_add_submessage(
|
||||
msg_type: str,
|
||||
content: str,
|
||||
) -> None:
|
||||
"""Should be called while holding a SELECT FOR UPDATE lock
|
||||
(e.g. via access_message(..., lock_message=True)) on the
|
||||
Message row, to prevent race conditions.
|
||||
"""
|
||||
submessage = SubMessage(
|
||||
sender_id=sender_id,
|
||||
message_id=message_id,
|
||||
@@ -2160,7 +2164,7 @@ def do_add_submessage(
|
||||
ums = UserMessage.objects.filter(message_id=message_id)
|
||||
target_user_ids = [um.user_profile_id for um in ums]
|
||||
|
||||
send_event(realm, event, target_user_ids)
|
||||
transaction.on_commit(lambda: send_event(realm, event, target_user_ids))
|
||||
|
||||
|
||||
def notify_reaction_update(
|
||||
|
||||
Reference in New Issue
Block a user