Skip to content

Commit 6cd40d3

Browse files
committed
fix: Megolm sessions become invalid after restarting client
This bug seems to be in the sdk for 5 years already without anyone noticing. The method loadInboundGroupSession seems to return the wrong variable when loading the session from the key. While the outboundgroupsession loading method relies on an inbound group session, it silently marks the outbound group session as invalid on every restart and creates a new one. This means we never reuse megolm sessions after restarting the client. Fixing this will probably reduce the amount of megolm sessions used in a conversation by a lot which could improve the performance and make the key backup more reliable.
1 parent 0874488 commit 6cd40d3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/encryption/key_manager.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ class KeyManager {
289289
dbSess.sessionId != sessionId) {
290290
return null;
291291
}
292-
roomInboundGroupSessions[sessionId] = dbSess;
293-
return sess;
292+
return roomInboundGroupSessions[sessionId] = dbSess;
294293
}
295294

296295
Map<String, Map<String, bool>> _getDeviceKeyIdMap(
@@ -348,6 +347,8 @@ class KeyManager {
348347
sess.outboundGroupSession!.session_id(),
349348
);
350349
if (inboundSess == null) {
350+
Logs().w('No inbound megolm session found for outbound session!');
351+
assert(inboundSess != null);
351352
wipe = true;
352353
}
353354

0 commit comments

Comments
 (0)