Skip to content

Commit 0cfd51f

Browse files
committed
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.
1 parent a62c607 commit 0cfd51f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/crypto/algorithms/megolm.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ class MegolmEncryption extends EncryptionAlgorithm {
292292
// takes the previous OutboundSessionInfo, and considers whether to create
293293
// a new one. Also shares the key with any (new) devices in the room.
294294
//
295-
// Returns the successful session whether keyshare succeeds or not.
296-
//
297295
// returns a promise which resolves once the keyshare is successful.
298296
const setup = async (oldSession: OutboundSessionInfo | null): Promise<OutboundSessionInfo> => {
299297
const sharedHistory = isRoomSharedHistory(room);
@@ -302,11 +300,11 @@ class MegolmEncryption extends EncryptionAlgorithm {
302300

303301
try {
304302
await this.shareSession(devicesInRoom, sharedHistory, singleOlmCreationPhase, blocked, session);
303+
return session;
305304
} catch (e) {
306305
logger.error(`Failed to ensure outbound session in ${this.roomId}`, e);
306+
throw e;
307307
}
308-
309-
return session;
310308
};
311309

312310
// first wait for the previous share to complete

0 commit comments

Comments
 (0)