Skip to content

Commit 6141078

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 ab4e24f commit 6141078

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,19 @@ 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+
// https://github.com/element-hq/element-web/issues/30988
147+
if (outgoingRequests.length > 0) {
148+
// We call doProcessOutgoingRequests but since we expect that we are
149+
// already processing outgoing requests, this call will not kick off
150+
// the processing loop, but just set `nextLoopDeferred` and return,
151+
// which will mean we loop one more time.
152+
this.doProcessOutgoingRequests().catch((e) => {
153+
this.logger.warn("processOutgoingRequests: Error re-checking outgoing requests", e);
154+
});
155+
}
142156
}
143157
}

0 commit comments

Comments
 (0)