Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Isolate reconnectWebSocket pings to survive CONNECTING sockets (#17680)

Caleb Gates97baccaa0e8a
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index f715b74c7a..00aca4738e 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -213,10 +213,22 @@ const siyuanApp = new App();
// https://github.com/siyuan-note/siyuan/issues/8441
window.reconnectWebSocket = () => {
- window.siyuan.ws.send("ping", {});
- window.siyuan.mobile.docks.file.send("ping", {});
- window.siyuan.mobile.editor.protyle.ws.send("ping", {});
- window.siyuan.mobile.popEditor?.protyle.ws.send("ping", {});
+ // 后台唤醒时任一 socket 可能仍在 CONNECTING,调用 send 会抛 InvalidStateError,
+ // 单独 try/catch 防止首个错误中断整个 ping 序列;下次 reconnectWebSocket 会再次尝试
+ const tryPing = (m?: { send: (cmd: string, p: Record<string, unknown>) => void }) => {
+ if (!m) {
+ return;
+ }
+ try {
+ m.send("ping", {});
+ } catch (e) {
+ console.warn("reconnectWebSocket: ping skipped", e);
+ }
+ };
+ tryPing(window.siyuan.ws);
+ tryPing(window.siyuan.mobile.docks.file);
+ tryPing(window.siyuan.mobile.editor.protyle.ws);
+ tryPing(window.siyuan.mobile.popEditor?.protyle.ws);
};
window.lockscreenByMode = () => {
if (window.siyuan.config.system.lockScreenMode === 1) {