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

Fix spurious session corruption error #12280

Merged
merged 7 commits into from
Feb 26, 2024
Merged
Changes from 2 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
67 changes: 39 additions & 28 deletions src/stores/LifecycleStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import { SyncState } from "matrix-js-sdk/src/matrix";
import { MINIMUM_MATRIX_VERSION, SUPPORTED_MATRIX_VERSIONS } from "matrix-js-sdk/src/version-support";
import { logger } from "matrix-js-sdk/src/logger";

import { Action } from "../dispatcher/actions";
import dis from "../dispatcher/dispatcher";
Expand Down Expand Up @@ -61,6 +62,7 @@ class LifecycleStore extends AsyncStore<IState> {
case "MatrixActions.sync": {
if (payload.state === SyncState.Syncing && payload.prevState !== SyncState.Syncing) {
richvdh marked this conversation as resolved.
Show resolved Hide resolved
// We've reconnected to the server: update server version support
// This is async but we don't care about the result, so just fire & forget.
checkServerVersions();
}

Expand All @@ -84,37 +86,46 @@ class LifecycleStore extends AsyncStore<IState> {
}

async function checkServerVersions(): Promise<void> {
const client = MatrixClientPeg.get();
if (!client) return;
for (const version of SUPPORTED_MATRIX_VERSIONS) {
// Check if the server supports this spec version. (`isVersionSupported` caches the response, so this loop will
// only make a single HTTP request).
// Note that although we do this on a reconnect, we cache the server's versions in memory
// indefinitely, so it will only ever trigger the toast on the first connection after a fresh
// restart of the client.
if (await client.isVersionSupported(version)) {
// we found a compatible spec version
return;
try {
const client = MatrixClientPeg.get();
if (!client) return;
for (const version of SUPPORTED_MATRIX_VERSIONS) {
// Check if the server supports this spec version. (`isVersionSupported` caches the response, so this loop will
// only make a single HTTP request).
// Note that although we do this on a reconnect, we cache the server's versions in memory
// indefinitely, so it will only ever trigger the toast on the first connection after a fresh
// restart of the client (which has just happened since it's started syncing, so this should
// never actually cause a request).)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's accurate. Or rather, it's accurate, but not for the reason given. The sync loop doesn't populate the serverVersionsPromise which is used by isVersionSupported.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, in my brief investigation it appeared to only do a single request, but not 100% sure so I've just removed that bit of the comment.

if (await client.isVersionSupported(version)) {
// we found a compatible spec version
return;
}
}
}

const toastKey = "LEGACY_SERVER";
ToastStore.sharedInstance().addOrReplaceToast({
key: toastKey,
title: _t("unsupported_server_title"),
props: {
description: _t("unsupported_server_description", {
version: MINIMUM_MATRIX_VERSION,
brand: SdkConfig.get().brand,
}),
acceptLabel: _t("action|ok"),
onAccept: () => {
ToastStore.sharedInstance().dismissToast(toastKey);
// This is retrospective doc having debated about the exactyl what this toast is for, but
dbkr marked this conversation as resolved.
Show resolved Hide resolved
// our guess is that it's a nudge to update, or ask your HS admin to update your Homeserver
// after a new version of Element has come out, in a way that doesn't lock you out of all
// your messages.
const toastKey = "LEGACY_SERVER";
ToastStore.sharedInstance().addOrReplaceToast({
key: toastKey,
title: _t("unsupported_server_title"),
props: {
description: _t("unsupported_server_description", {
version: MINIMUM_MATRIX_VERSION,
brand: SdkConfig.get().brand,
}),
acceptLabel: _t("action|ok"),
onAccept: () => {
ToastStore.sharedInstance().dismissToast(toastKey);
},
},
},
component: GenericToast,
priority: 98,
});
component: GenericToast,
priority: 98,
});
} catch (e) {
logger.warn("Failed to check server versions", e);
}
}

let singletonLifecycleStore: LifecycleStore | null = null;
Expand Down
Loading