Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

embed_links: Take a lock on the message object while editing.

Alex Vandiverde63000db6fb
diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py
index 6a80ca9c8c3..aa8452129e2 100644
--- a/zerver/worker/queue_processors.py
+++ b/zerver/worker/queue_processors.py
@@ -869,12 +869,16 @@ class FetchLinksEmbedData(QueueProcessingWorker):
"Time spent on get_link_embed_data for %s: %s", url, time.time() - start_time
)
- message = Message.objects.get(id=event["message_id"])
- # If the message changed, we will run this task after updating the message
- # in zerver.actions.message_edit.check_update_message
- if message.content != event["message_content"]:
- return
- if message.content is not None:
+ with transaction.atomic():
+ message = Message.objects.select_for_update().get(id=event["message_id"])
+ # If the message changed, we will run this task after updating the message
+ # in zerver.actions.message_edit.check_update_message
+ if message.content != event["message_content"]:
+ return
+
+ if message.content is None:
+ return
+
query = UserMessage.objects.filter(
message=message.id,
)