fix: Don't re-play m.dummy to_device events
If both ends had m.dummy events queued as last messages an an olm session corrupted, then the clients landed in an infinite game of ping-pong. It was so stable, that the clients could have won the ping-pong world championships!
This commit is contained in:
parent
7a3553839c
commit
b41c7b1bc6
|
|
@ -667,11 +667,16 @@ class OlmManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final lastSentMessage = json.decode(lastSentMessageRes.first);
|
final lastSentMessage = json.decode(lastSentMessageRes.first);
|
||||||
|
// We do *not* want to re-play m.dummy events, as they hold no value except of saying
|
||||||
|
// what olm session is the most recent one. In fact, if we *do* replay them, then
|
||||||
|
// we can easily land in an infinite ping-pong trap!
|
||||||
|
if (lastSentMessage['type'] != EventTypes.Dummy) {
|
||||||
// okay, time to send the message!
|
// okay, time to send the message!
|
||||||
await client.sendToDeviceEncrypted(
|
await client.sendToDeviceEncrypted(
|
||||||
[device], lastSentMessage['type'], lastSentMessage['content']);
|
[device], lastSentMessage['type'], lastSentMessage['content']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
for (final sessions in olmSessions.values) {
|
for (final sessions in olmSessions.values) {
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,30 @@ void main() {
|
||||||
FakeMatrixApi.calledEndpoints.keys.any(
|
FakeMatrixApi.calledEndpoints.keys.any(
|
||||||
(k) => k.startsWith('/client/r0/sendToDevice/m.room.encrypted')),
|
(k) => k.startsWith('/client/r0/sendToDevice/m.room.encrypted')),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
// don't replay if the last event is m.dummy itself
|
||||||
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
|
await client.database.setLastSentMessageUserDeviceKey(
|
||||||
|
json.encode({
|
||||||
|
'type': 'm.dummy',
|
||||||
|
'content': {},
|
||||||
|
}),
|
||||||
|
client.id,
|
||||||
|
userId,
|
||||||
|
deviceId);
|
||||||
|
event = ToDeviceEvent(
|
||||||
|
sender: userId,
|
||||||
|
type: 'm.dummy',
|
||||||
|
content: {},
|
||||||
|
encryptedContent: {
|
||||||
|
'sender_key': senderKey,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await client.encryption.olmManager.handleToDeviceEvent(event);
|
||||||
|
expect(
|
||||||
|
FakeMatrixApi.calledEndpoints.keys.any(
|
||||||
|
(k) => k.startsWith('/client/r0/sendToDevice/m.room.encrypted')),
|
||||||
|
false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('dispose client', () async {
|
test('dispose client', () async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue