electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.51k stars 1.73k forks source link

Auto Updater EPERM Issues #7784

Open ThatKawaiiSam opened 10 months ago

ThatKawaiiSam commented 10 months ago

We have Sentry enabled throughout our Application and have noticed a considerable amount of errors with the Auto Updater in regards to some update files operations not being permitted.

Screenshot 2023-09-16 at 11 44 29 pm

We do not modify any of the core functionality of the updater and use it mostly out of the box with a few additions around when quitAndInstall() is called ensuring that we don't update when in the dock.

Happy to provide any additional context if needed.

mmaietta commented 10 months ago

Are you distributing both portable and nsis targets? Can you please post your electron-builder config?

okkidev01 commented 10 months ago

@mmaietta I had the same issue, my sentry log is like that: Electron-Builder Version: 23.6.0 Node Version: 16.17.1 Electron Version: 19.0.0 Electron Type (current, beta, nightly): current Target: Windows, macOS image

all of this error happened on Windows image

my packaging config is blow: "nsis": { "oneClick": false, "perMachine": false, "allowToChangeInstallationDirectory": true, "shortcutName": OKKI${ENV_NAME}, "include": "./scripts/installer.nsh", "differentialPackage": false, "packElevateHelper": true, "guid": OKKI${ENV_NAME} }, "win": { "target": [ { "target": "nsis", "arch": [ "ia32", "x64" ] } ], "signingHashAlgorithms":['sha1', 'sha256'], "sign": "./scripts/signWin.js", "verifyUpdateCodeSignature": false, "signDlls": true, "timeStampServer": "http://timestamp.digicert.com" },

ThatKawaiiSam commented 10 months ago

Are you distributing both portable and nsis targets? Can you please post your electron-builder config?

Here is the builder-effective-config.yaml

directories:
  output: release
  buildResources: build
generateUpdatesFilesForAllChannels: true
appId: com.moonsworth.client
extraMetadata:
  version: 3.1.0
productName: Lunar Client
files:
  - filter:
      - build/**/*
      - dist/**/*
      - dist-electron/**/*
      - '!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}'
      - '!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}'
      - '!**/node_modules/*.d.ts'
      - '!**/node_modules/.bin'
      - '!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}'
      - '!.editorconfig'
      - '!**/._*'
      - '!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,.gitignore,.gitattributes}'
      - '!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}'
      - '!**/{appveyor.yml,.travis.yml,circle.yml}'
      - '!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}'
      - '!**/node_modules/typescript/**/*'
      - '!**/node_modules/register-scheme/**/*'
protocols:
  - name: lunarclient
    schemes:
      - lunarclient
win:
  target: nsis-web
  icon: build/icon.png
  signingHashAlgorithms:
    - sha256
  sign: ./winSign.js
mac:
  category: public.app-category.games
  hardenedRuntime: true
  artifactName: ${productName} v${version}.${ext}
  entitlements: build/entitlements.plist
  entitlementsInherit: build/entitlements.plist
  target:
    - dmg
    - zip
  icon: build/icon-macos.png
  notarize: {}
linux:
  target: AppImage
dmg:
  title: Lunar Client
  writeUpdateInfo: false
  window:
    width: 1000
    height: 776
  iconSize: 120
  contents:
    - x: 296
      'y': 496
    - x: 704
      'y': 496
      type: link
      name: Applications
      path: /Applications
nsisWeb:
  oneClick: true
  perMachine: false
  license: build/license_en.txt
  artifactName: ${productName} v${version}.${ext}
  installerIcon: build/icon-installer.ico
  uninstallerIcon: build/icon-uninstaller.ico
  installerHeaderIcon: build/icon.ico
  uninstallDisplayName: Uninstall ${productName}
  installerSidebar: build/sidebar.bmp
  uninstallerSidebar: build/sidebar.bmp
  differentialPackage: false
publish:
  - provider: generic
    url: https://launcherupdates.lunarclientcdn.com
    publishAutoUpdate: true
    useMultipleRangeRequest: false
electronVersion: 25.3.0
ThatKawaiiSam commented 9 months ago

@mmaietta do you need any more information?

mmaietta commented 9 months ago

Idk tbh. I was hoping it was due to portable being used as I recall there being a caveat with it. Since it's nsis-web, I have no idea what could be causing it. I personally am not able to debug it any further on my arm64 mac though. Will need community members to debug it and propose a solution. electron-builder currently detects some error responses, but it's not inclusive of EPERM. https://github.com/electron-userland/electron-builder/blob/4c9b8296b9104a28ad9bccf643eec3d6c0dff6ab/packages/electron-updater/src/NsisUpdater.ts#L162-L170 Not sure how to handle EPERM on Windows.

For AppImage updates, we just use chmod https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/AppImageUpdater.ts#L71

Any ideas on how we can attend to EPERM issues?

ThatKawaiiSam commented 9 months ago

Idk tbh. I was hoping it was due to portable being used as I recall there being a caveat with it. Since it's nsis-web, I have no idea what could be causing it. I personally am not able to debug it any further on my arm64 mac though. Will need community members to debug it and propose a solution. electron-builder currently detects some error responses, but it's not inclusive of EPERM.

https://github.com/electron-userland/electron-builder/blob/4c9b8296b9104a28ad9bccf643eec3d6c0dff6ab/packages/electron-updater/src/NsisUpdater.ts#L162-L170

Not sure how to handle EPERM on Windows. For AppImage updates, we just use chmod https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/AppImageUpdater.ts#L71

Any ideas on how we can attend to EPERM issues?

I did read in another issue that it may be potentially due to a race condition with checking the update twice, although we do have a locking mechanism within our application and were not able to reproduce: https://github.com/electron-userland/electron-builder/issues/5408#issuecomment-1705086586

ThatKawaiiSam commented 7 months ago

Just wanted to bump this as we did another production deploy of our application today. We also see EBUSY errors aswell as per the screenshot:

Screenshot 2023-12-31 at 5 34 27 pm
mmaietta commented 6 months ago

Does anyone know if there is a way to detect via javascript whether a resource is no longer locked? I'm not familiar with EPERM

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

ThatKawaiiSam commented 2 months ago

Not entirely sure but thought I would just mention that this is still an ongoing issue

k1nz commented 6 days ago

Here is my resolution, I hope this can help you.

class Updater {
  #downloading = false
  #autoUpdater
  #init() {
     this.#autoUpdater = new NsisUpdater({
     // config...
     })

     // disable auto download
     this.#autoUpdater.autoDownload = false

      this.#autoUpdater.on('update-avaliable' , async (info) => {
        await this.downloadUpdate()
      }

      this.#autoUpdater.on('error', (info) => {
        this.#downloading = false
      }

      this.#autoUpdater.on('update-downloaded', (info) => {
        this.#downloading = false
      }
  }

  async downloadUpdate() {
    if (this.#downloading) {
      return
    }
    this.#downloading = true
    await this.#autoUpdater.downloadUpdate()
  }
}