diff --git a/packages/app/src/Cache/index.ts b/packages/app/src/Cache/index.ts index 0ef001cd..b4e81e2e 100644 --- a/packages/app/src/Cache/index.ts +++ b/packages/app/src/Cache/index.ts @@ -36,7 +36,10 @@ export async function initRelayWorker() { if (!conn) { conn = await tryUseCacheRelay("ws://umbrel:4848"); } - if (conn) return; + if (conn) { + window.location.reload(); + return; + } } else if (Relay instanceof ConnectionCacheRelay) { await Relay.connection.connect(true); return; @@ -44,6 +47,9 @@ export async function initRelayWorker() { } catch (e) { localStorage.removeItem("cache-relay"); console.error(e); + if (cacheRelay) { + window.location.reload(); + } } try { diff --git a/packages/system/src/connection.ts b/packages/system/src/connection.ts index 788bed1c..442a5d7b 100644 --- a/packages/system/src/connection.ts +++ b/packages/system/src/connection.ts @@ -45,6 +45,7 @@ export class Connection extends EventEmitter implements Co #activeRequests = new Set(); #connectStarted = false; #syncModule?: ConnectionSyncModule; + #wasUp = false; id: string; readonly address: string; @@ -169,6 +170,7 @@ export class Connection extends EventEmitter implements Co #onOpen(wasReconnect: boolean) { this.#downCount = 0; this.#connectStarted = false; + this.#wasUp = true; this.#log(`Open!`); this.#setupEphemeral(); this.emit("connected", wasReconnect); @@ -176,12 +178,12 @@ export class Connection extends EventEmitter implements Co } #onClose(e: WebSocket.CloseEvent) { - // remote server closed the connection, dont re-connect - if (!this.#closing) { + // if not explicity closed or closed after, start re-connect timer + if (this.#wasUp && !this.#closing) { this.#downCount++; this.#reconnectTimer(e); } else { - this.#log(`Closed!`); + this.#log(`Closed: connecting=${this.#connectStarted}, closing=${this.#closing}`); this.#downCount = 0; if (this.ReconnectTimer) { clearTimeout(this.ReconnectTimer); @@ -206,9 +208,7 @@ export class Connection extends EventEmitter implements Co this.ReconnectTimer = undefined; try { this.connect(); - } catch { - this.emit("disconnect", -1); - } + } catch {} }, this.ConnectTimeout); }