Skip to content

Commit 506de74

Browse files
committed
Re-check outgoing requests after processing them
... in case any new requests have been added during processing. Fixes element-hq/element-web#30988
1 parent 633a5a8 commit 506de74

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

spec/integ/crypto/cross-signing.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ describe("cross-signing", () => {
403403
const isCrossSigningReady = await aliceClient.getCrypto()!.isCrossSigningReady();
404404

405405
expect(isCrossSigningReady).toBeFalsy();
406-
});
406+
}, 10000);
407407
});
408408

409409
describe("getCrossSigningKeyId", () => {

spec/unit/rust-crypto/OutgoingRequestsManager.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ describe("OutgoingRequestsManager", () => {
9292
await secondRequest;
9393
await thirdRequest;
9494

95-
// outgoingRequests should be called twice in total, as the second and third requests are
96-
// processed in the same loop.
97-
expect(olmMachine.outgoingRequests).toHaveBeenCalledTimes(2);
95+
// outgoingRequests should be called three times in total:
96+
// 1. the first time,
97+
// 2. the second and third requests processed in the same loop, and
98+
// 3. checking that all requests are finished
99+
expect(olmMachine.outgoingRequests).toHaveBeenCalledTimes(3);
98100

99101
expect(processor.makeOutgoingRequest).toHaveBeenCalledTimes(3);
100102
expect(processor.makeOutgoingRequest).toHaveBeenCalledWith(request1);

src/rust-crypto/OutgoingRequestsManager.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,29 @@ export class OutgoingRequestsManager {
139139
this.logger.error(`Failed to process outgoing request ${request.type}: ${e}`);
140140
}
141141
}
142+
143+
// If we handled any requests this time, more may have been queued as
144+
// part of that handling, so do an extra check to make sure we handle
145+
// them immediately. See
146+
// If we handled any requests this time, more may have been queued as
147+
// part of that handling.
148+
//
149+
// For example, we may have processed a `/keys/claim` request, which
150+
// meant the rust side could establish an Olm session and is now ready to
151+
// send out an `m.secret.send` message.
152+
// (See https://github.com/element-hq/element-web/issues/30988.)
153+
//
154+
// So, if we have processed any requests, flag that we need make another
155+
// pass around the outgoing-requests loop, to make sure we handle any
156+
// pending requests immediately.
157+
if (outgoingRequests.length > 0) {
158+
// We call doProcessOutgoingRequests but since we expect that we are
159+
// already processing outgoing requests, this call will not kick off
160+
// the processing loop, but just set `nextLoopDeferred` and return,
161+
// which will mean we loop one more time.
162+
this.doProcessOutgoingRequests().catch((e) => {
163+
this.logger.warn("processOutgoingRequests: Error re-checking outgoing requests", e);
164+
});
165+
}
142166
}
143167
}

0 commit comments

Comments
 (0)