You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Add debug logs to encryption prep
This extra debug logs may help isolate the cause of https://github.com/vector-im/element-web/issues/16194. These changes also fix a related (but most likely different) failure mode: if a failure occurred in the `encryptionPreparation` async task, we would skip trying to prepare in all future attempts for that room. This change ensures prep failures are logged and we resume prep attempts on the next call from the application.
This commit is contained in:
@@ -264,11 +264,14 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
|
|||||||
await Promise.all([
|
await Promise.all([
|
||||||
(async () => {
|
(async () => {
|
||||||
// share keys with devices that we already have a session for
|
// share keys with devices that we already have a session for
|
||||||
|
logger.debug(`Sharing keys with existing Olm sessions in ${this._roomId}`);
|
||||||
await this._shareKeyWithOlmSessions(
|
await this._shareKeyWithOlmSessions(
|
||||||
session, key, payload, olmSessions,
|
session, key, payload, olmSessions,
|
||||||
);
|
);
|
||||||
|
logger.debug(`Shared keys with existing Olm sessions in ${this._roomId}`);
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(async () => {
|
||||||
|
logger.debug(`Sharing keys with new Olm sessions in ${this._roomId}`);
|
||||||
const errorDevices = [];
|
const errorDevices = [];
|
||||||
|
|
||||||
// meanwhile, establish olm sessions for devices that we don't
|
// meanwhile, establish olm sessions for devices that we don't
|
||||||
@@ -319,8 +322,10 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
|
|||||||
} else {
|
} else {
|
||||||
await this._notifyFailedOlmDevices(session, key, errorDevices);
|
await this._notifyFailedOlmDevices(session, key, errorDevices);
|
||||||
}
|
}
|
||||||
|
logger.debug(`Shared keys with new Olm sessions in ${this._roomId}`);
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(async () => {
|
||||||
|
logger.debug(`Notifying blocked devices in ${this._roomId}`);
|
||||||
// also, notify blocked devices that they're blocked
|
// also, notify blocked devices that they're blocked
|
||||||
const blockedMap = {};
|
const blockedMap = {};
|
||||||
for (const [userId, userBlockedDevices] of Object.entries(blocked)) {
|
for (const [userId, userBlockedDevices] of Object.entries(blocked)) {
|
||||||
@@ -336,6 +341,7 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this._notifyBlockedDevices(session, blockedMap);
|
await this._notifyBlockedDevices(session, blockedMap);
|
||||||
|
logger.debug(`Notified blocked devices in ${this._roomId}`);
|
||||||
})(),
|
})(),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
@@ -348,6 +354,11 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
|
|||||||
// first wait for the previous share to complete
|
// first wait for the previous share to complete
|
||||||
const prom = this._setupPromise.then(prepareSession);
|
const prom = this._setupPromise.then(prepareSession);
|
||||||
|
|
||||||
|
// Ensure any failures are logged for debugging
|
||||||
|
prom.catch(e => {
|
||||||
|
logger.error(`Failed to ensure outbound session in ${this._roomId}`, e);
|
||||||
|
});
|
||||||
|
|
||||||
// _setupPromise resolves to `session` whether or not the share succeeds
|
// _setupPromise resolves to `session` whether or not the share succeeds
|
||||||
this._setupPromise = prom.then(returnSession, returnSession);
|
this._setupPromise = prom.then(returnSession, returnSession);
|
||||||
|
|
||||||
@@ -840,12 +851,22 @@ MegolmEncryption.prototype.prepareToEncrypt = function(room) {
|
|||||||
// We're already preparing something, so don't do anything else.
|
// We're already preparing something, so don't do anything else.
|
||||||
// FIXME: check if we need to restart
|
// FIXME: check if we need to restart
|
||||||
// (https://github.com/matrix-org/matrix-js-sdk/issues/1255)
|
// (https://github.com/matrix-org/matrix-js-sdk/issues/1255)
|
||||||
|
const elapsedTime = Date.now() - this.encryptionPreparationMetadata.startTime
|
||||||
|
logger.debug(
|
||||||
|
`Already started preparing to encrypt for ${this._roomId} ` +
|
||||||
|
`${elapsedTime} ms ago, skipping`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`Preparing to encrypt events for ${this._roomId}`);
|
logger.debug(`Preparing to encrypt events for ${this._roomId}`);
|
||||||
|
|
||||||
|
this.encryptionPreparationMetadata = {
|
||||||
|
startTime: Date.now(),
|
||||||
|
};
|
||||||
this.encryptionPreparation = (async () => {
|
this.encryptionPreparation = (async () => {
|
||||||
|
try {
|
||||||
|
logger.debug(`Getting devices in ${this._roomId}`);
|
||||||
const [devicesInRoom, blocked] = await this._getDevicesInRoom(room);
|
const [devicesInRoom, blocked] = await this._getDevicesInRoom(room);
|
||||||
|
|
||||||
if (this._crypto.getGlobalErrorOnUnknownDevices()) {
|
if (this._crypto.getGlobalErrorOnUnknownDevices()) {
|
||||||
@@ -855,9 +876,16 @@ MegolmEncryption.prototype.prepareToEncrypt = function(room) {
|
|||||||
this._removeUnknownDevices(devicesInRoom);
|
this._removeUnknownDevices(devicesInRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug(`Ensuring outbound session in ${this._roomId}`);
|
||||||
await this._ensureOutboundSession(devicesInRoom, blocked, true);
|
await this._ensureOutboundSession(devicesInRoom, blocked, true);
|
||||||
|
|
||||||
|
logger.debug(`Ready to encrypt events for ${this._roomId}`);
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(`Failed to prepare to encrypt events for ${this._roomId}`, e);
|
||||||
|
} finally {
|
||||||
|
delete this.encryptionPreparationMetadata;
|
||||||
delete this.encryptionPreparation;
|
delete this.encryptionPreparation;
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user