Skip to content

Commit ca0e845

Browse files
authoredAug 14, 2021
fix(electron-updater): null object error when MacUpdater logs server port before it is listening (#6149)
1 parent 2656b5e commit ca0e845

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

Diff for: ‎.changeset/stale-carrots-listen.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"electron-updater": patch
3+
---
4+
5+
fix(electron-updater): `null` object error when MacUpdater attempts to log the server port before it is listening

Diff for: ‎packages/electron-updater/src/MacUpdater.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ export class MacUpdater extends AppUpdater {
8080
const logContext = `fileToProxy=${zipFileInfo.url.href}`
8181
this.debug(`Creating proxy server for native Squirrel.Mac (${logContext})`)
8282
const server = createServer()
83+
this.debug(`Proxy server for native Squirrel.Mac is created (${logContext})`)
8384
server.on("close", () => {
8485
log.info(`Proxy server for native Squirrel.Mac is closed (${logContext})`)
8586
})
8687

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

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

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

1 commit comments

Comments
 (1)

aguynamedben commented on Sep 5, 2021

@aguynamedben
Contributor

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.