diff --git a/src/app/pages/client/BackgroundNotifications.tsx b/src/app/pages/client/BackgroundNotifications.tsx index 30d8383a0..6aa9f2e72 100644 --- a/src/app/pages/client/BackgroundNotifications.tsx +++ b/src/app/pages/client/BackgroundNotifications.tsx @@ -100,8 +100,13 @@ const startBackgroundClient = async (session: Session): Promise => timelineLimit: 1, }; - await startClient(mx, startOpts); - return mx; + try { + await startClient(mx, startOpts); + return mx; + } catch (error) { + stopClient(mx); + throw error; + } }; /** @@ -302,7 +307,8 @@ export function BackgroundNotifications() { await waitForSync(mx); - if (disposed || current.get(session.userId) !== mx) { + if (disposed) return; + if (current.get(session.userId) !== mx) { stopClient(mx); return; } @@ -330,6 +336,12 @@ export function BackgroundNotifications() { }); } + if (disposed) return; + if (current.get(session.userId) !== mx) { + stopClient(mx); + return; + } + const pushProcessor = mx.pushProcessor; const handleAccountData = (event: MatrixEvent) => {