From 6cd40d3f9198733cccb00d962984948e3ba21bdb Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 3 Feb 2025 09:12:30 +0100 Subject: [PATCH] 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. --- lib/encryption/key_manager.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index 3d18032d..ade2762d 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -289,8 +289,7 @@ class KeyManager { dbSess.sessionId != sessionId) { return null; } - roomInboundGroupSessions[sessionId] = dbSess; - return sess; + return roomInboundGroupSessions[sessionId] = dbSess; } Map> _getDeviceKeyIdMap( @@ -348,6 +347,8 @@ class KeyManager { sess.outboundGroupSession!.session_id(), ); if (inboundSess == null) { + Logs().w('No inbound megolm session found for outbound session!'); + assert(inboundSess != null); wipe = true; }