1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Add logging on decryption retries

For https://github.com/vector-im/riot-web/issues/13473
This commit is contained in:
David Baker
2020-05-01 17:36:49 +01:00
parent 3d495b0753
commit d699e98346
2 changed files with 13 additions and 5 deletions

View File

@@ -1601,9 +1601,11 @@ MegolmDecryption.prototype._retryDecryption = async function(senderKey, sessionI
return true; return true;
} }
logger.debug("Retrying decryption on events", [...pending]);
await Promise.all([...pending].map(async (ev) => { await Promise.all([...pending].map(async (ev) => {
try { try {
await ev.attemptDecryption(this._crypto); await ev.attemptDecryption(this._crypto, true);
} catch (e) { } catch (e) {
// don't die if something goes wrong // don't die if something goes wrong
} }

View File

@@ -390,11 +390,12 @@ utils.extend(MatrixEvent.prototype, {
* @internal * @internal
* *
* @param {module:crypto} crypto crypto module * @param {module:crypto} crypto crypto module
* @param {bool} isRetry True if this is a retry (enables more logging)
* *
* @returns {Promise} promise which resolves (to undefined) when the decryption * @returns {Promise} promise which resolves (to undefined) when the decryption
* attempt is completed. * attempt is completed.
*/ */
attemptDecryption: async function(crypto) { attemptDecryption: async function(crypto, isRetry) {
// start with a couple of sanity checks. // start with a couple of sanity checks.
if (!this.isEncrypted()) { if (!this.isEncrypted()) {
throw new Error("Attempt to decrypt event which isn't encrypted"); throw new Error("Attempt to decrypt event which isn't encrypted");
@@ -424,7 +425,7 @@ utils.extend(MatrixEvent.prototype, {
return this._decryptionPromise; return this._decryptionPromise;
} }
this._decryptionPromise = this._decryptionLoop(crypto); this._decryptionPromise = this._decryptionLoop(crypto, isRetry);
return this._decryptionPromise; return this._decryptionPromise;
}, },
@@ -469,7 +470,7 @@ utils.extend(MatrixEvent.prototype, {
return recipients; return recipients;
}, },
_decryptionLoop: async function(crypto) { _decryptionLoop: async function(crypto, isRetry) {
// make sure that this method never runs completely synchronously. // make sure that this method never runs completely synchronously.
// (doing so would mean that we would clear _decryptionPromise *before* // (doing so would mean that we would clear _decryptionPromise *before*
// it is set in attemptDecryption - and hence end up with a stuck // it is set in attemptDecryption - and hence end up with a stuck
@@ -486,13 +487,18 @@ utils.extend(MatrixEvent.prototype, {
res = this._badEncryptedMessage("Encryption not enabled"); res = this._badEncryptedMessage("Encryption not enabled");
} else { } else {
res = await crypto.decryptEvent(this); res = await crypto.decryptEvent(this);
if (isRetry) {
logger.info(`Decrypted event on retry (id=${this.getId()})`);
}
} }
} catch (e) { } catch (e) {
if (e.name !== "DecryptionError") { if (e.name !== "DecryptionError") {
// not a decryption error: log the whole exception as an error // not a decryption error: log the whole exception as an error
// (and don't bother with a retry) // (and don't bother with a retry)
const re = isRetry ? 're' : '';
logger.error( logger.error(
`Error decrypting event (id=${this.getId()}): ${e.stack || e}`, `Error ${re}decrypting event ` +
`(id=${this.getId()}): ${e.stack || e}`,
); );
this._decryptionPromise = null; this._decryptionPromise = null;
this._retryDecryption = false; this._retryDecryption = false;