fix: Rapid retry behavior (#10776)

This commit is contained in:
Tom Moor
2025-12-03 20:25:12 -05:00
committed by GitHub
parent 1d2f6e7c55
commit 55f21bfbb3
5 changed files with 22 additions and 12 deletions
@@ -6,6 +6,7 @@ import {
useMemo,
useEffect,
forwardRef,
useRef,
} from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
@@ -26,6 +27,7 @@ import useStores from "~/hooks/useStores";
import { AwarenessChangeEvent } from "~/types";
import Logger from "~/utils/Logger";
import { homePath } from "~/utils/routeHelpers";
import { sleep } from "@shared/utils/timers";
type Props = EditorProps & {
id: string;
@@ -52,6 +54,7 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
const history = useHistory();
const { t } = useTranslation();
const currentUser = useCurrentUser();
const retryCount = useRef(0);
const { presence, auth, ui } = useStores();
const [editorVersionBehind, setEditorVersionBehind] = useState(false);
const [showCursorNames, setShowCursorNames] = useState(false);
@@ -105,15 +108,21 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
);
provider.on("authenticationFailed", () => {
void auth
.fetchAuth()
.then(() => {
provider.setConfiguration({ token: auth.collaborationToken });
provider.connect();
})
.catch(() => {
history.replace(homePath());
});
provider.shouldConnect = false;
retryCount.current++;
sleep(retryCount.current * 1000 - 1000).then(() =>
auth
.fetchAuth()
.then(() => {
provider.setConfiguration({ token: auth.collaborationToken });
provider.connect();
provider.shouldConnect = true;
})
.catch(() => {
history.replace(homePath());
})
);
});
provider.on("awarenessChange", (event: AwarenessChangeEvent) => {
@@ -153,6 +162,7 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
provider.on("synced", () => {
presence.touch(documentId, currentUser.id, false);
setRemoteSynced(true);
retryCount.current = 0;
});
provider.on("close", (ev: MessageEvent) => {
@@ -11,7 +11,7 @@ import {
Event,
} from "@server/types";
import fetch from "@server/utils/fetch";
import { sleep } from "@server/utils/timers";
import { sleep } from "@shared/utils/timers";
import env from "../env";
import { presentMessageAttachment } from "../presenters/messageAttachment";
@@ -1,7 +1,7 @@
import { Server } from "@hocuspocus/server";
import WebSocket from "ws";
import EDITOR_VERSION from "@shared/editor/version";
import { sleep } from "@server/utils/timers";
import { sleep } from "@shared/utils/timers";
import { ConnectionLimitExtension } from "./ConnectionLimitExtension";
import { EditorVersionExtension } from "./EditorVersionExtension";
+1 -1
View File
@@ -1,6 +1,6 @@
import groupBy from "lodash/groupBy";
import Logger from "@server/logging/Logger";
import { sleep } from "./timers";
import { sleep } from "@shared/utils/timers";
export enum ShutdownOrder {
first = 0,