Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron-auto-updater request can download so fast that the first few chunks arrive before ensureDirPromise has finished for configurePipes to run #1081

Closed
Jashepp opened this issue Jan 4, 2017 · 1 comment · May be fixed by qcif/data-curator#563
Labels

Comments

@Jashepp
Copy link

Jashepp commented Jan 4, 2017

Module Versions:
electron-builder@10.16.0
electron-builder-http@10.16.0
electron-auto-updater@0.9.0

Building For: electron@1.4.13 (windows 10 x64)

Hi, I have electron-auto-updater setup to download from a generic server.
I have been having issues of getting an error: "Error: SHA2 checksum mismatch, expected xxx, got xyx" (different hashes each time I build different setup files).

I had a look at the downloaded files, and noticed that some parts at the beginning of the file is missing.
After messing around and trying to figure out what was going on, I found out that some of the starting chunks of the request to download the update file, were not being parsed through DigestTransform via configurePipes in /packages/electron-builder-http/src/httpExecutor, because ensureDirPromise has not yet completed in /packages/electron-auto-updater/src/electronHttpExecutor.ts#L74.

This may not have shown as an issue for those using other publish providers, where creating a directory is faster than receiving the first chunks of the request, but in my case, the server is very close (and will be for users using my application), even though I have an SSD, the network request was still faster.

My local fix was to create the directory first before net.request is called, which caused the downloads to no longer be corrupted. maybe another way is to pause the stream until after the directory is made?
edit at: /packages/electron-auto-updater/src/electronHttpExecutor.ts#L53

    ensureDirPromise.then(() => {
      const request = net.request(requestOpts, (response: Electron.IncomingMessage) => {
        if (response.statusCode >= 400) {
          callback(new Error(`Cannot download "${url}", status ${response.statusCode}: ${response.statusMessage}`))
          return
        }

        const redirectUrl = safeGetHeader(response, "location")
        if (redirectUrl != null) {
          if (redirectCount < maxRedirects) {
            this.doDownload(redirectUrl, destination, redirectCount++, options, callback)
          }
          else {
            callback(new Error(`Too many redirects (> ${maxRedirects})`))
          }
          return
        }

        if (!checkSha2(safeGetHeader(response, "X-Checksum-Sha2"), options.sha2, callback)) {
          return
        }

        configurePipes(options, response, destination, callback)
      })
      this.addTimeOutHandler(request, callback)
      request.on("error", callback)
      request.end()
    })
    .catch(callback)
@develar
Copy link
Member

develar commented Jan 4, 2017

electron-auto-updater@0.9.0

Please use 0.9.1

Duplicates #1077

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants