From 9fef4638bfe07329c92b113cddf52987dff657e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 23 Nov 2022 14:02:01 +0100 Subject: [PATCH] Don't swallow up errors coming from the shareSession call A call to ensureSession() has two steps: 1. prepareSession(), where an outbound group session might get created or rotated 2. shareSession(), where an outbound group session might get encrypted and queued up to be sent to other devices Both of those calls may mostly fail due to storage errors, yet only the errors from prepareSession get propagated to the caller. Errors from prepareSession will mean that you can't get an outbound group session so you can't encrypt an event. Errors from shareSession, especially if the error happens in the part where the to-device requests are queued up to be sent out, mean that other people will not be able to decrypt the events that will get encrypted using the outbound group session. Both of those cases are catastrophic, the second case is just much harder to debug, since the error happens on another device at some arbitrary point in the future. Let's just return the error instead, people can then retry and the storage issue might have been resolved, or at least the error becomes visible when it happens. --- src/crypto/algorithms/megolm.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/crypto/algorithms/megolm.ts b/src/crypto/algorithms/megolm.ts index e002ffa3d91..e8816569339 100644 --- a/src/crypto/algorithms/megolm.ts +++ b/src/crypto/algorithms/megolm.ts @@ -277,19 +277,12 @@ export class MegolmEncryption extends EncryptionAlgorithm { // takes the previous OutboundSessionInfo, and considers whether to create // a new one. Also shares the key with any (new) devices in the room. // - // Returns the successful session whether keyshare succeeds or not. - // // returns a promise which resolves once the keyshare is successful. const setup = async (oldSession: OutboundSessionInfo | null): Promise => { const sharedHistory = isRoomSharedHistory(room); - const session = await this.prepareSession(devicesInRoom, sharedHistory, oldSession); - try { - await this.shareSession(devicesInRoom, sharedHistory, singleOlmCreationPhase, blocked, session); - } catch (e) { - logger.error(`Failed to ensure outbound session in ${this.roomId}`, e); - } + await this.shareSession(devicesInRoom, sharedHistory, singleOlmCreationPhase, blocked, session); return session; };