Skip to content

Commit

Permalink
fix(electron-updater): null object error when MacUpdater logs serve…
Browse files Browse the repository at this point in the history
…r port before it is listening (#6149)
  • Loading branch information
tessro committed Aug 14, 2021
1 parent 2656b5e commit ca0e845
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/stale-carrots-listen.md
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix(electron-updater): `null` object error when MacUpdater attempts to log the server port before it is listening
4 changes: 3 additions & 1 deletion packages/electron-updater/src/MacUpdater.ts
Expand Up @@ -80,16 +80,17 @@ export class MacUpdater extends AppUpdater {
const logContext = `fileToProxy=${zipFileInfo.url.href}`
this.debug(`Creating proxy server for native Squirrel.Mac (${logContext})`)
const server = createServer()
this.debug(`Proxy server for native Squirrel.Mac is created (${logContext})`)
server.on("close", () => {
log.info(`Proxy server for native Squirrel.Mac is closed (${logContext})`)
})

// must be called after server is listening, otherwise address is null
function getServerUrl(): string {
const address = server.address() as AddressInfo
return `http://127.0.0.1:${address.port}`
}

this.debug(`Proxy server for native Squirrel.Mac is created (address=${getServerUrl()}, ${logContext})`)
return await new Promise<Array<string>>((resolve, reject) => {
// insecure random is ok
const fileUrl = `/${Date.now().toString(16)}-${Math.floor(Math.random() * 9999).toString(16)}.zip`
Expand Down Expand Up @@ -145,6 +146,7 @@ export class MacUpdater extends AppUpdater {

this.debug(`Proxy server for native Squirrel.Mac is starting to listen (${logContext})`)
server.listen(0, "127.0.0.1", () => {
this.debug(`Proxy server for native Squirrel.Mac is listening (address=${getServerUrl()}, ${logContext})`)
this.nativeUpdater.setFeedURL({
url: getServerUrl(),
headers: { "Cache-Control": "no-cache" },
Expand Down

1 comment on commit ca0e845

@aguynamedben
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing. This was a painful one for us. Luckily we caught it right after a deploy, but it would have broken autoupdates for all of our users.

Please sign in to comment.