Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7e5de92

Browse files
authored
Refine UISI autorageshake conditions to cut down on false alarms (#7650)
The AutoRageshakeStore now only starts submitting rageshakes after the initial sync has completed, and provides a short grace period for decryption failures to resolve.
1 parent f99ae6d commit 7e5de92

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/stores/AutoRageshakeStore.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ limitations under the License.
1515
*/
1616

1717
import { MatrixEvent } from "matrix-js-sdk/src";
18+
import { sleep } from "matrix-js-sdk/src/utils";
19+
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
1820

1921
import SdkConfig from '../SdkConfig';
2022
import sendBugReport from '../rageshake/submit-rageshake';
@@ -23,14 +25,17 @@ import { AsyncStoreWithClient } from './AsyncStoreWithClient';
2325
import { ActionPayload } from '../dispatcher/payloads';
2426
import SettingsStore from "../settings/SettingsStore";
2527

26-
// Minimum interval of 5 minutes between reports, especially important when we're doing an initial sync with a lot of decryption errors
27-
const RAGESHAKE_INTERVAL = 5*60*1000;
28+
// Minimum interval of 1 minute between reports
29+
const RAGESHAKE_INTERVAL = 60000;
30+
// Before rageshaking, wait 5 seconds and see if the message has successfully decrypted
31+
const GRACE_PERIOD = 5000;
2832
// Event type for to-device messages requesting sender auto-rageshakes
2933
const AUTO_RS_REQUEST = "im.vector.auto_rs_request";
3034

3135
interface IState {
3236
reportedSessionIds: Set<string>;
3337
lastRageshakeTime: number;
38+
initialSyncCompleted: boolean;
3439
}
3540

3641
/**
@@ -45,9 +50,11 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
4550
super(defaultDispatcher, {
4651
reportedSessionIds: new Set<string>(),
4752
lastRageshakeTime: 0,
53+
initialSyncCompleted: false,
4854
});
4955
this.onDecryptionAttempt = this.onDecryptionAttempt.bind(this);
5056
this.onDeviceMessage = this.onDeviceMessage.bind(this);
57+
this.onSyncStateChange = this.onSyncStateChange.bind(this);
5158
}
5259

5360
public static get instance(): AutoRageshakeStore {
@@ -64,6 +71,7 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
6471
if (this.matrixClient) {
6572
this.matrixClient.on('Event.decrypted', this.onDecryptionAttempt);
6673
this.matrixClient.on('toDeviceEvent', this.onDeviceMessage);
74+
this.matrixClient.on('sync', this.onSyncStateChange);
6775
}
6876
}
6977

@@ -75,9 +83,14 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
7583
}
7684

7785
private async onDecryptionAttempt(ev: MatrixEvent): Promise<void> {
86+
if (!this.state.initialSyncCompleted) { return; }
87+
7888
const wireContent = ev.getWireContent();
7989
const sessionId = wireContent.session_id;
8090
if (ev.isDecryptionFailure() && !this.state.reportedSessionIds.has(sessionId)) {
91+
await sleep(GRACE_PERIOD);
92+
if (!ev.isDecryptionFailure()) { return; }
93+
8194
const newReportedSessionIds = new Set(this.state.reportedSessionIds);
8295
await this.updateState({ reportedSessionIds: newReportedSessionIds.add(sessionId) });
8396

@@ -114,6 +127,12 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
114127
}
115128
}
116129

130+
private async onSyncStateChange(_state: SyncState, _prevState: SyncState, data: ISyncStateData) {
131+
if (!this.state.initialSyncCompleted) {
132+
await this.updateState({ initialSyncCompleted: !!data.nextSyncToken });
133+
}
134+
}
135+
117136
private async onDeviceMessage(ev: MatrixEvent): Promise<void> {
118137
if (ev.getType() !== AUTO_RS_REQUEST) return;
119138
const messageContent = ev.getContent();

0 commit comments

Comments
 (0)