From 2f1f44880e7ba46340139590a86e8e7ff65afc2a Mon Sep 17 00:00:00 2001 From: Taea <88346289+adrastaea@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:34:36 -0400 Subject: [PATCH] Fix autoUpdater Memory Leak (#2608) * divide listener setup and update check * update changelog --- CHANGELOG.md | 6 ++++++ packages/desktop/src/main/main.ts | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02777cda37..7a9e4c6a24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [unreleased] + +### Fixes + +* Fixed memory leak associated with autoUpdater ([#2606](https://github.com/TryQuiet/quiet/issues/2606)) + ## [2.3.1] ### Fixes diff --git a/packages/desktop/src/main/main.ts b/packages/desktop/src/main/main.ts index 340867b7d8..0617bc9e64 100644 --- a/packages/desktop/src/main/main.ts +++ b/packages/desktop/src/main/main.ts @@ -260,17 +260,19 @@ const isNetworkError = (errorObject: { message: string }) => { ) } -export const checkForUpdate = async (win: BrowserWindow) => { +export const checkForUpdate = async () => { try { await autoUpdater.checkForUpdates() } catch (error) { if (isNetworkError(error)) { - logger.error('Network Error') + logger.warn(`updater: ${error.message}`) } else { - logger.error('Unknown Error') - logger.error(error == null ? 'unknown' : (error.stack || error).toString()) + logger.error(error) } } +} + +const setupUpdater = async () => { autoUpdater.on('checking-for-update', () => { logger.info('updater: checking-for-update') }) @@ -285,7 +287,9 @@ export const checkForUpdate = async (win: BrowserWindow) => { }) autoUpdater.on('update-downloaded', () => { logger.info('updater: update-downloaded') - win.webContents.send('newUpdateAvailable') + if (isBrowserWindow(mainWindow)) { + mainWindow.webContents.send('newUpdateAvailable') + } }) autoUpdater.on('before-quit-for-update', () => { logger.info('updater: before-quit-for-update') @@ -505,12 +509,10 @@ app.on('ready', async () => { } } - await checkForUpdate(mainWindow) + await setupUpdater() + await checkForUpdate() setInterval(async () => { - if (!isBrowserWindow(mainWindow)) { - throw new Error(`mainWindow is on unexpected type ${mainWindow}`) - } - await checkForUpdate(mainWindow) + await checkForUpdate() }, updaterInterval) })