Skip to content

MatrixRTC: MembershipManager, add a request timeout to restartDelayedEvent #4896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions spec/unit/matrixrtc/MembershipManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,31 @@
expect(connectEmit).toHaveBeenCalledWith(Status.Disconnecting, Status.Disconnected);
});
});
describe("local timeout error handling", () => {
it("retries sending restart delayed leave request after configure local timeout", async () => {
const manager = new MembershipManager(
{ delayedEventRestartLocalTimeoutMs: 1000 },
room,
client,
() => undefined,
);
manager.join([focus], focusActive);
expect(client._unstable_sendDelayedStateEvent).toHaveBeenCalledTimes(1);
await jest.advanceTimersByTimeAsync(1);

expect(client._unstable_updateDelayedEvent).toHaveBeenCalledTimes(1);

// Simulate a local timeout error
// (client._unstable_updateDelayedEvent as Mock<any>).mockRejectedValue(new HTTPError("timeout", 408));
// Advance the timers so that the retry happens.
await jest.advanceTimersByTimeAsync(1100);
expect(client._unstable_updateDelayedEvent).toHaveBeenCalledWith("id", "restart", {

Check failure on line 623 in spec/unit/matrixrtc/MembershipManager.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

MembershipManager › local timeout error handling › retries sending restart delayed leave request after configure local timeout

expect(jest.fn()).toHaveBeenCalledWith(...expected) - Expected + Received "id", "restart", Object { "localTimeoutMs": 1000, - "priority": "auto", }, Number of calls: 1 at Object.toHaveBeenCalledWith (spec/unit/matrixrtc/MembershipManager.spec.ts:623:57) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 623 in spec/unit/matrixrtc/MembershipManager.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

MembershipManager › local timeout error handling › retries sending restart delayed leave request after configure local timeout

expect(jest.fn()).toHaveBeenCalledWith(...expected) - Expected + Received "id", "restart", Object { "localTimeoutMs": 1000, - "priority": "auto", }, Number of calls: 1 at Object.toHaveBeenCalledWith (spec/unit/matrixrtc/MembershipManager.spec.ts:623:57) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
localTimeoutMs: 1000,
priority: "auto",
});
});
});

describe("server error handling", () => {
// Types of server error: 429 rate limit with no retry-after header, 429 with retry-after, 50x server error (maybe retry every second), connection/socket timeout
describe("retries sending delayed leave event", () => {
Expand Down
9 changes: 9 additions & 0 deletions src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ export interface MembershipConfig {
/** @deprecated renamed to `networkErrorRetryMs`*/
callMemberEventRetryDelayMinimum?: number;

/**
* The time (in milliseconds) after which a we consider a delayed event restart http request to have failed.
* Setting this to a lower value will result in more frequent retries but also a higher chance of failiour.
*
* the default local timeout in the js-sdk is 5 seconds.
* @default 5000
*/
delayedEventRestartLocalTimeoutMs?: number;

/**
* If true, use the new to-device transport for sending encryption keys.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/matrixrtc/MembershipManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { UpdateDelayedEventAction } from "../@types/requests.ts";
import { type MatrixClient } from "../client.ts";
import { UnsupportedDelayedEventsEndpointError } from "../errors.ts";
import { ConnectionError, HTTPError, MatrixError } from "../http-api/errors.ts";
import { type IRequestOpts } from "../http-api/index.ts";
import { type Logger, logger as rootLogger } from "../logger.ts";
import { type Room } from "../models/room.ts";
import { type CallMembership, DEFAULT_EXPIRE_DURATION, type SessionMembershipData } from "./CallMembership.ts";
Expand Down Expand Up @@ -374,6 +375,9 @@ export class MembershipManager
return this.joinConfig?.maximumNetworkErrorRetryCount ?? 10;
}

private get delayedEventRestartLocalTimeoutMs(): number | undefined {
return this.joinConfig?.delayedEventRestartLocalTimeoutMs;
}
// LOOP HANDLER:
private async membershipLoopHandler(type: MembershipActionType): Promise<ActionUpdate> {
switch (type) {
Expand Down Expand Up @@ -525,8 +529,11 @@ export class MembershipManager
}

private async restartDelayedEvent(delayId: string): Promise<ActionUpdate> {
const requestOptions: IRequestOpts = {
localTimeoutMs: this.delayedEventRestartLocalTimeoutMs,
};
return await this.client
._unstable_updateDelayedEvent(delayId, UpdateDelayedEventAction.Restart)
._unstable_updateDelayedEvent(delayId, UpdateDelayedEventAction.Restart, requestOptions)
.then(() => {
this.resetRateLimitCounter(MembershipActionType.RestartDelayedEvent);
return createInsertActionUpdate(
Expand Down
Loading