Skip to content

Commit 3215e7b

Browse files
committed
WIP to remove workaround for MSC4140
Removes workaround for element-hq/synapse#17810 not having landed
1 parent 9f9be70 commit 3215e7b

2 files changed

Lines changed: 26 additions & 77 deletions

File tree

src/matrixrtc/NewMembershipManager.ts

Lines changed: 24 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,22 @@ export interface IMembershipManager {
7373
/* MembershipActionTypes:
7474
7575
┌─────────────────────┐
76-
│SendFirstDelayedEvent│
76+
| SendDelayedEvent |
7777
└─────────────────────┘
7878
7979
8080
┌─────────────┐
8181
┌────────────│SendJoinEvent│────────────┐
8282
│ └─────────────┘ │
83-
│ ┌─────┐ ┌──────┐ │ ┌──────┐
84-
▼ ▼ │ │ ▼ ▼ ▼ │
85-
┌────────────┐ │ │ ┌───────────────────┐ │
86-
│UpdateExpiry│ │ │ │RestartDelayedEvent│ │
87-
└────────────┘ │ │ └───────────────────┘ │
88-
│ │ │ │ │ │
89-
└─────┘ └──────┘ │ │
90-
│ │
91-
┌────────────────────┐ │ │
92-
│SendMainDelayedEvent│◄───────┘ │
93-
└───────────────────┬┘ │
94-
│ │
95-
└─────────────────────┘
96-
STOP ALL ABOVE
83+
│ ┌─────┐ ┌──────┐ │
84+
▼ ▼ │ │ ▼ ▼
85+
┌────────────┐ │ │ ┌───────────────────┐
86+
│UpdateExpiry│ │ │ │RestartDelayedEvent│
87+
└────────────┘ │ │ └───────────────────┘
88+
│ │ │ │
89+
└─────┘ └──────┘
90+
91+
STOP ALL ABOVE
9792
9893
┌───────────────────────────────┐
9994
│ SendScheduledDelayedLeaveEvent│
@@ -110,22 +105,19 @@ export interface IMembershipManager {
110105
* @internal
111106
*/
112107
export enum MembershipActionType {
113-
SendFirstDelayedEvent = "SendFirstDelayedEvent",
108+
SendDelayedEvent = "SendDelayedEvent",
114109
// -> MembershipActionType.SendJoinEvent if successful
115110
// -> DelayedLeaveActionType.SendFirstDelayedEvent on error, retry sending the first delayed event.
116111
SendJoinEvent = "SendJoinEvent",
117112
// -> MembershipActionType.SendJoinEvent if we run into a rate limit and need to retry
118113
// -> MembershipActionType.Update if we successfully send the join event then schedule the expire event update
119-
// -> DelayedLeaveActionType.RestartDelayedEvent to recheck the delayed event
114+
// -> DelayedLeaveActionType.RestartDelayedEvent on success start updating the delayed event
120115
RestartDelayedEvent = "RestartDelayedEvent",
121116
// -> DelayedLeaveActionType.SendMainDelayedEvent on missing delay id but there is a rtc state event
122117
// -> DelayedLeaveActionType.SendFirstDelayedEvent on missing delay id and there is no state event
123118
// -> DelayedLeaveActionType.RestartDelayedEvent on success we schedule the next restart
124119
UpdateExpiry = "UpdateExpiry",
125120
// -> MembershipActionType.Update if the timeout has passed so the next update is required.
126-
SendMainDelayedEvent = "SendMainDelayedEvent",
127-
// -> DelayedLeaveActionType.RestartDelayedEvent on success start updating the delayed event
128-
// -> DelayedLeaveActionType.SendMainDelayedEvent on error try again
129121
SendScheduledDelayedLeaveEvent = "SendScheduledDelayedLeaveEvent",
130122
// -> MembershipActionType.SendLeaveEvent on failiour (not found) we need to send the leave manually and cannot use the scheduled delayed event
131123
// -> DelayedLeaveActionType.SendScheduledDelayedLeaveEvent on error we try again.
@@ -244,7 +236,7 @@ export class MembershipManager implements IMembershipManager {
244236
// If one of these actions are scheduled or are getting inserted in the next iteration, we should already
245237
// take care of our missing membership.
246238
const sendingMembershipActions = [
247-
MembershipActionType.SendFirstDelayedEvent,
239+
MembershipActionType.SendDelayedEvent,
248240
MembershipActionType.SendJoinEvent,
249241
];
250242
logger.warn("Missing own membership: force re-join");
@@ -381,7 +373,7 @@ export class MembershipManager implements IMembershipManager {
381373
private async membershipLoopHandler(type: MembershipActionType): Promise<ActionUpdate> {
382374
this.oldStatus = this.status;
383375
switch (type) {
384-
case MembershipActionType.SendFirstDelayedEvent: {
376+
case MembershipActionType.SendDelayedEvent: {
385377
// Before we start we check if we come from a state where we have a delay id.
386378
if (!this.state.delayId) {
387379
return this.sendFirstDelayedLeaveEvent(); // Normal case without any previous delayed id.
@@ -399,17 +391,10 @@ export class MembershipManager implements IMembershipManager {
399391
case MembershipActionType.RestartDelayedEvent: {
400392
if (!this.state.delayId) {
401393
// Delay id got reset. This action was used to check if the hs canceled the delayed event when the join state got sent.
402-
return createInsertActionUpdate(
403-
this.state.hasMemberStateEvent
404-
? MembershipActionType.SendMainDelayedEvent
405-
: MembershipActionType.SendFirstDelayedEvent,
406-
);
394+
return createInsertActionUpdate(MembershipActionType.SendDelayedEvent);
407395
}
408396
return this.restartDelayedEvent(this.state.delayId);
409397
}
410-
case MembershipActionType.SendMainDelayedEvent: {
411-
return this.sendMainDelayedEvent();
412-
}
413398
case MembershipActionType.SendScheduledDelayedLeaveEvent: {
414399
// We are already good
415400
if (!this.state.hasMemberStateEvent) {
@@ -453,13 +438,13 @@ export class MembershipManager implements IMembershipManager {
453438
)
454439
.then((response) => {
455440
// On success we reset retries and set delayId.
456-
this.state.rateLimitRetries.set(MembershipActionType.SendFirstDelayedEvent, 0);
457-
this.state.networkErrorRetries.set(MembershipActionType.SendFirstDelayedEvent, 0);
441+
this.state.rateLimitRetries.set(MembershipActionType.SendDelayedEvent, 0);
442+
this.state.networkErrorRetries.set(MembershipActionType.SendDelayedEvent, 0);
458443
this.state.delayId = response.delay_id;
459444
return createInsertActionUpdate(MembershipActionType.SendJoinEvent);
460445
})
461446
.catch((e) => {
462-
const repeatActionType = MembershipActionType.SendFirstDelayedEvent;
447+
const repeatActionType = MembershipActionType.SendDelayedEvent;
463448
if (this.manageMaxDelayExceededSituation(e)) {
464449
return createInsertActionUpdate(repeatActionType);
465450
}
@@ -483,11 +468,11 @@ export class MembershipManager implements IMembershipManager {
483468
._unstable_updateDelayedEvent(delayId, UpdateDelayedEventAction.Cancel)
484469
.then(() => {
485470
this.state.delayId = undefined;
486-
this.resetRateLimitCounter(MembershipActionType.SendFirstDelayedEvent);
487-
return createReplaceActionUpdate(MembershipActionType.SendFirstDelayedEvent);
471+
this.resetRateLimitCounter(MembershipActionType.SendDelayedEvent);
472+
return createReplaceActionUpdate(MembershipActionType.SendDelayedEvent);
488473
})
489474
.catch((e) => {
490-
const repeatActionType = MembershipActionType.SendFirstDelayedEvent;
475+
const repeatActionType = MembershipActionType.SendDelayedEvent;
491476
const update = this.actionUpdateFromErrors(e, repeatActionType, "updateDelayedEvent");
492477
if (update) return update;
493478

@@ -526,7 +511,7 @@ export class MembershipManager implements IMembershipManager {
526511
const repeatActionType = MembershipActionType.RestartDelayedEvent;
527512
if (this.isNotFoundError(e)) {
528513
this.state.delayId = undefined;
529-
return createInsertActionUpdate(MembershipActionType.SendMainDelayedEvent);
514+
return createInsertActionUpdate(MembershipActionType.SendDelayedEvent);
530515
}
531516
// If the HS does not support delayed events we wont reschedule.
532517
if (this.isUnsupportedDelayedEndpoint(e)) return {};
@@ -540,40 +525,6 @@ export class MembershipManager implements IMembershipManager {
540525
});
541526
}
542527

543-
private async sendMainDelayedEvent(): Promise<ActionUpdate> {
544-
return await this.client
545-
._unstable_sendDelayedStateEvent(
546-
this.room.roomId,
547-
{
548-
delay: this.membershipServerSideExpiryTimeout,
549-
},
550-
EventType.GroupCallMemberPrefix,
551-
{}, // leave event
552-
this.stateKey,
553-
)
554-
.then((response) => {
555-
this.state.delayId = response.delay_id;
556-
this.resetRateLimitCounter(MembershipActionType.SendMainDelayedEvent);
557-
return createInsertActionUpdate(
558-
MembershipActionType.RestartDelayedEvent,
559-
this.membershipKeepAlivePeriod,
560-
);
561-
})
562-
.catch((e) => {
563-
const repeatActionType = MembershipActionType.SendMainDelayedEvent;
564-
// Don't do any other delayed event work if its not supported.
565-
if (this.isUnsupportedDelayedEndpoint(e)) return {};
566-
567-
if (this.manageMaxDelayExceededSituation(e)) {
568-
return createInsertActionUpdate(repeatActionType);
569-
}
570-
const update = this.actionUpdateFromErrors(e, repeatActionType, "updateDelayedEvent");
571-
if (update) return update;
572-
573-
throw Error("Could not send delayed event, even though delayed events are supported. " + e);
574-
});
575-
}
576-
577528
private async sendScheduledDelayedLeaveEventOrFallbackToSendLeaveEvent(delayId: string): Promise<ActionUpdate> {
578529
return await this.client
579530
._unstable_updateDelayedEvent(delayId, UpdateDelayedEventAction.Send)
@@ -875,9 +826,8 @@ export class MembershipManager implements IMembershipManager {
875826
if (actions.length === 1) {
876827
const { type } = actions[0];
877828
switch (type) {
878-
case MembershipActionType.SendFirstDelayedEvent:
829+
case MembershipActionType.SendDelayedEvent:
879830
case MembershipActionType.SendJoinEvent:
880-
case MembershipActionType.SendMainDelayedEvent:
881831
return Status.Connecting;
882832
case MembershipActionType.UpdateExpiry: // where no delayed events
883833
return Status.Connected;
@@ -891,8 +841,7 @@ export class MembershipManager implements IMembershipManager {
891841
const types = actions.map((a) => a.type);
892842
// normal state for connected with delayed events
893843
if (
894-
(types.includes(MembershipActionType.RestartDelayedEvent) ||
895-
types.includes(MembershipActionType.SendMainDelayedEvent)) &&
844+
types.includes(MembershipActionType.RestartDelayedEvent) &&
896845
types.includes(MembershipActionType.UpdateExpiry)
897846
) {
898847
return Status.Connected;

src/matrixrtc/NewMembershipManagerActionScheduler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class ActionScheduler {
6969
return;
7070
}
7171
this.running = true;
72-
this._actions = [{ ts: Date.now(), type: MembershipActionType.SendFirstDelayedEvent }];
72+
this._actions = [{ ts: Date.now(), type: MembershipActionType.SendDelayedEvent }];
7373
try {
7474
while (this._actions.length > 0) {
7575
// Sort so next (smallest ts) action is at the beginning
@@ -123,7 +123,7 @@ export class ActionScheduler {
123123
}
124124

125125
public initiateJoin(): void {
126-
this.wakeup?.({ replace: [{ ts: Date.now(), type: MembershipActionType.SendFirstDelayedEvent }] });
126+
this.wakeup?.({ replace: [{ ts: Date.now(), type: MembershipActionType.SendDelayedEvent }] });
127127
}
128128
public initiateLeave(): void {
129129
this.wakeup?.({ replace: [{ ts: Date.now(), type: MembershipActionType.SendScheduledDelayedLeaveEvent }] });

0 commit comments

Comments
 (0)