Skip to content

Commit 198c9a2

Browse files
committed
Add logging to in progress Olm sessions
It seems like this might be where element-hq/element-web#16194 is deadlocking.
1 parent fccf08e commit 198c9a2

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/crypto/OlmDevice.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,10 @@ OlmDevice.prototype.createInboundSession = async function(
621621
* @return {Promise<string[]>} a list of known session ids for the device
622622
*/
623623
OlmDevice.prototype.getSessionIdsForDevice = async function(theirDeviceIdentityKey) {
624+
const log = getPrefixedLogger("[getSessionIdsForDevice]");
625+
624626
if (this._sessionsInProgress[theirDeviceIdentityKey]) {
625-
logger.log("waiting for olm session to be created");
627+
log.debug(`Waiting for Olm session for ${theirDeviceIdentityKey} to be created`);
626628
try {
627629
await this._sessionsInProgress[theirDeviceIdentityKey];
628630
} catch (e) {
@@ -640,7 +642,7 @@ OlmDevice.prototype.getSessionIdsForDevice = async function(theirDeviceIdentityK
640642
},
641643
);
642644
},
643-
getPrefixedLogger("[getSessionIdsForDevice]"),
645+
log,
644646
);
645647

646648
return sessionIds;
@@ -703,8 +705,10 @@ OlmDevice.prototype.getSessionIdForDevice = async function(
703705
* @return {Array.<{sessionId: string, hasReceivedMessage: Boolean}>}
704706
*/
705707
OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey, nowait) {
708+
const log = getPrefixedLogger("[getSessionInfoForDevice]");
709+
706710
if (this._sessionsInProgress[deviceIdentityKey] && !nowait) {
707-
logger.log("waiting for olm session to be created");
711+
log.debug(`Waiting for Olm session for ${deviceIdentityKey} to be created`);
708712
try {
709713
await this._sessionsInProgress[deviceIdentityKey];
710714
} catch (e) {
@@ -730,7 +734,7 @@ OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey,
730734
}
731735
});
732736
},
733-
getPrefixedLogger("[getSessionInfoForDevice]"),
737+
log,
734738
);
735739

736740
return info;

src/crypto/olmlib.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,23 @@ export async function ensureOlmSessionsForDevices(
232232
continue;
233233
}
234234

235+
const forWhom = `for ${key} (${userId}:${deviceId})`;
236+
log.debug(`Ensuring Olm session ${forWhom}`);
235237
if (!olmDevice._sessionsInProgress[key]) {
236238
// pre-emptively mark the session as in-progress to avoid race
237239
// conditions. If we find that we already have a session, then
238240
// we'll resolve
241+
log.debug(`Marking Olm session in progress ${forWhom}`);
239242
olmDevice._sessionsInProgress[key] = new Promise(
240243
(resolve, reject) => {
241244
resolveSession[key] = {
242245
resolve: (...args) => {
246+
log.debug(`Resolved Olm session in progress ${forWhom}`);
243247
delete olmDevice._sessionsInProgress[key];
244248
resolve(...args);
245249
},
246250
reject: (...args) => {
251+
log.debug(`Rejected Olm session in progress ${forWhom}`);
247252
delete olmDevice._sessionsInProgress[key];
248253
reject(...args);
249254
},
@@ -254,6 +259,7 @@ export async function ensureOlmSessionsForDevices(
254259
const sessionId = await olmDevice.getSessionIdForDevice(
255260
key, resolveSession[key],
256261
);
262+
log.debug(`Got Olm session ${sessionId} ${forWhom}`);
257263
if (sessionId !== null && resolveSession[key]) {
258264
// we found a session, but we had marked the session as
259265
// in-progress, so unmark it and unblock anything that was
@@ -264,9 +270,9 @@ export async function ensureOlmSessionsForDevices(
264270
}
265271
if (sessionId === null || force) {
266272
if (force) {
267-
log.info(`Forcing new Olm session for ${userId}:${deviceId}`);
273+
log.info(`Forcing new Olm session ${forWhom}`);
268274
} else {
269-
log.info(`Making new Olm session for ${userId}:${deviceId}`);
275+
log.info(`Making new Olm session ${forWhom}`);
270276
}
271277
devicesWithoutSession.push([userId, deviceId]);
272278
}

0 commit comments

Comments
 (0)