Skip to content

Commit c2b464a

Browse files
authored
Avoid rapidly retrying failed requests (#5146)
After #5109 we retry failed requests in a tight loop, instead of once every sync. When requests are consistently failing, e.g. when /keys/uploads is failing because of a duplicate OTK, this causes us to make many requests, causing load on the server. The fix is to reprocess the outgoing requests loop only if at least one request succeeded in the last batch. Fixes element-hq/element-web#31790
1 parent 4a75d2c commit c2b464a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/rust-crypto/OutgoingRequestsManager.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,13 @@ export class OutgoingRequestsManager {
127127

128128
const outgoingRequests: OutgoingRequest[] = await this.olmMachine.outgoingRequests();
129129

130+
let successes = 0;
130131
for (const request of outgoingRequests) {
131132
if (this.stopped) return;
132133
try {
133134
await logDuration(this.logger, `Make outgoing request ${request.type}`, async () => {
134135
await this.outgoingRequestProcessor.makeOutgoingRequest(request);
136+
successes++;
135137
});
136138
} catch (e) {
137139
// as part of the loop we silently ignore errors, but log them.
@@ -140,21 +142,22 @@ export class OutgoingRequestsManager {
140142
}
141143
}
142144

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
145+
// If we successfully handled any requests this time, more may have been queued as
147146
// part of that handling.
148147
//
149148
// For example, we may have processed a `/keys/claim` request, which
150149
// meant the rust side could establish an Olm session and is now ready to
151150
// send out an `m.secret.send` message.
152151
// (See https://github.com/element-hq/element-web/issues/30988.)
153152
//
154-
// So, if we have processed any requests, flag that we need make another
153+
// So, if we have successfully processed any requests, flag that we need to make another
155154
// pass around the outgoing-requests loop, to make sure we handle any
156155
// pending requests immediately.
157-
if (outgoingRequests.length > 0) {
156+
//
157+
// If all requests failed (or there weren't any) we don't want to retry them in a tight
158+
// loop. They will be retried after the next sync.
159+
// (See https://github.com/element-hq/element-web/issues/31790.)
160+
if (successes > 0) {
158161
// We call doProcessOutgoingRequests but since we expect that we are
159162
// already processing outgoing requests, this call will not kick off
160163
// the processing loop, but just set `nextLoopDeferred` and return,

0 commit comments

Comments
 (0)