MessageEngine sends potentially large number of useless messages
The issue can be reproduced in several different ways. Here's an example scenario:
- Alice creates a group conversation and invites a certain number of peers (I used 3 to generate the logs below)
- The peers accept Alice's invitation
- Alice invites Bob to join the group conversation, but Bob doesn't do anything (i.e. he neither accepts nor declines the invitation)
- Alice sends a message to the group
The exact number of messages exchanged via the MessageEngine as a result of the above steps varies, but I've seen cases where there were several hundreds in total. This appears to be the combined effect of three separate bugs:
- When Bob's device is notified of the message sent by Alice to the group, the
ConversationModule::Impl::fetchNewCommits
function is called, notices that the new message is for a conversation that Bob doesn't have on its device, and therefore sends a message to request an invitation for that conversation. The bug is that the function doesn't check if Bob has already received an invitation; thus, if Bob receives, say, 5 notifications for Alice's message, then he will also request 5 new invitations unnecessarily:
[1732215564.492|14145|conversation_module.cpp :2011] 43ab129ce8fd609df9d87b5a97b45b45bb0e6530 is asking a new invite for 4133cac75f8b84935900d034a61efb897ca10d96
[...]
[1732215564.492|14145|conversation_module.cpp :2011] 43ab129ce8fd609df9d87b5a97b45b45bb0e6530 is asking a new invite for 4133cac75f8b84935900d034a61efb897ca10d96
[...]
[1732215564.492|14145|conversation_module.cpp :2011] 43ab129ce8fd609df9d87b5a97b45b45bb0e6530 is asking a new invite for 4133cac75f8b84935900d034a61efb897ca10d96
[...]
[1732215564.493|14145|conversation_module.cpp :2011] 43ab129ce8fd609df9d87b5a97b45b45bb0e6530 is asking a new invite for 4133cac75f8b84935900d034a61efb897ca10d96
[...]
[1732215564.493|14145|conversation_module.cpp :2011] 43ab129ce8fd609df9d87b5a97b45b45bb0e6530 is asking a new invite for 4133cac75f8b84935900d034a61efb897ca10d96
- The
MessageEngine::onMessageSent
function doesn't behave correctly if it is called twice in a row for the same message (i.e. sametoken
argument), but with different values for theok
argument. More specifically, there is a problem if the function is first called withok == false
and then withok == true
, because the first call will set the message's status toIDLE
, which prevents the second call from setting to state toSENT
. This means that the same message can potentially get sent multiple times (4 in the example below) before its status is finally set toSENT
.
[1732215564.492|14053|message_engine.cpp :117 ] [message 2663233195457807] Reattempt sending
[1732215564.492|14053|message_engine.cpp :148 ] [message 2663233195457807] Message sent: failure
[1732215564.492|14051|message_engine.cpp :148 ] [message 2663233195457807] Message sent: success
[1732215564.492|14053|message_engine.cpp :191 ] [message 2663233195457807] Status changed to IDLE
[1732215564.492|14051|message_engine.cpp :194 ] [message 2663233195457807] State is not SENDING
[1732215564.493|14053|message_engine.cpp :117 ] [message 2663233195457807] Reattempt sending
[1732215564.493|14053|message_engine.cpp :148 ] [message 2663233195457807] Message sent: failure
[1732215564.493|14051|message_engine.cpp :148 ] [message 2663233195457807] Message sent: success
[1732215564.493|14053|message_engine.cpp :191 ] [message 2663233195457807] Status changed to IDLE
[1732215564.493|14051|message_engine.cpp :194 ] [message 2663233195457807] State is not SENDING
[1732215564.493|14053|message_engine.cpp :117 ] [message 2663233195457807] Reattempt sending
[1732215564.493|14053|message_engine.cpp :148 ] [message 2663233195457807] Message sent: failure
[1732215564.493|14051|message_engine.cpp :148 ] [message 2663233195457807] Message sent: success
[1732215564.493|14053|message_engine.cpp :191 ] [message 2663233195457807] Status changed to IDLE
[1732215564.493|14051|message_engine.cpp :194 ] [message 2663233195457807] State is not SENDING
[1732215564.498|14053|message_engine.cpp :117 ] [message 2663233195457807] Reattempt sending
[1732215564.498|14051|message_engine.cpp :148 ] [message 2663233195457807] Message sent: success
[1732215564.498|14053|message_engine.cpp :148 ] [message 2663233195457807] Message sent: failure
[1732215564.498|14051|message_engine.cpp :167 ] [message 2663233195457807] Status changed to SENT
[1732215564.499|14053|message_engine.cpp :197 ] [message 2663233195457807] Unable to find message
- The
JamiAccount::sendMessage
doesn't return after a message is successfully sent by the MessageChannelHandler in the case where thedeviceId
argument is empty (see line 3081 ofjamiaccount.cpp
on commit 0fc67d6c of the jami-daemon repo). Because of this, it incorrectly callsMessageEngine::onMessageSent
withok
set to false later (line 3162 ofjamiaccount.cpp
). This makes the race condition described above much more likely to happen than it would otherwise.