Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 76d44db

Browse files
committed
Stop adding a message_id to to-device messages
Currently, we add a `message_id` field to any to-device message that is sent by a local user to another local user, and then strip it off again before serving it to the user. This isn't terribly useful, because: 1. it can't be correlated in the sending/receiving clients 2. a single sendToDevice call, or federation EDU, can create multiple to-device messages all with the same message id, which again makes them less than useful for tracing. 3. It was never wired up for messages received over federation. So, let's stop doing that, in preparation for something better.
1 parent 6acb6d7 commit 76d44db

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

synapse/handlers/appservice.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,6 @@ async def _get_to_device_messages(
578578
device_id,
579579
), messages in recipient_device_to_messages.items():
580580
for message_json in messages:
581-
# Remove 'message_id' from the to-device message, as it's an internal ID
582-
message_json.pop("message_id", None)
583-
584581
message_payload.append(
585582
{
586583
"to_user_id": user_id,

synapse/handlers/devicemessage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ async def send_device_message(
216216
"""
217217
sender_user_id = requester.user.to_string()
218218

219-
message_id = random_string(16)
220-
set_tag(SynapseTags.TO_DEVICE_MESSAGE_ID, message_id)
221-
222219
log_kv({"number_of_to_device_messages": len(messages)})
223220
set_tag("sender", sender_user_id)
224221
local_messages = {}
@@ -247,7 +244,6 @@ async def send_device_message(
247244
"content": message_content,
248245
"type": message_type,
249246
"sender": sender_user_id,
250-
"message_id": message_id,
251247
}
252248
for device_id, message_content in by_device.items()
253249
}
@@ -267,7 +263,11 @@ async def send_device_message(
267263

268264
remote_edu_contents = {}
269265
for destination, messages in remote_messages.items():
270-
log_kv({"destination": destination})
266+
# The EDU contains a "message_id" property which is used for
267+
# idempotence. Make up a random one.
268+
message_id = random_string(16)
269+
log_kv({"destination": destination, "message_id": message_id})
270+
271271
remote_edu_contents[destination] = {
272272
"messages": messages,
273273
"sender": sender_user_id,

synapse/handlers/sync.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,13 +1602,6 @@ async def _generate_sync_entry_for_to_device(
16021602
user_id, device_id, since_stream_id, now_token.to_device_key
16031603
)
16041604

1605-
for message in messages:
1606-
# We pop here as we shouldn't be sending the message ID down
1607-
# `/sync`
1608-
message_id = message.pop("message_id", None)
1609-
if message_id:
1610-
set_tag(SynapseTags.TO_DEVICE_MESSAGE_ID, message_id)
1611-
16121605
logger.debug(
16131606
"Returning %d to-device messages between %d and %d (current token: %d)",
16141607
len(messages),

0 commit comments

Comments
 (0)