Skip to content

Commit 70b105b

Browse files
authored
Ensure app store initialisation retry logic is applied
We had retry logic before but it wasn't working because `AppStore.update()` never throws it silently fails to be safe to run in a loop without causing exceptions. Now we have custom logic to only pull the default app repo and throw on error wrapped in the same retry logic as before. This is needed as a short term fix for the DHCP race condition where we try to initialise the App Store before the device has an IP.
1 parent 5b1fa4a commit 70b105b

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

packages/umbreld/source/modules/apps/app-repository.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,7 @@ export default class AppRepository {
122122
this.logger.verbose(`${this.url} is already up to date`)
123123
} else {
124124
this.logger.verbose(`Newer version of ${this.url} available, updating`)
125-
try {
126-
await this.atomicClone()
127-
} catch (error) {
128-
this.logger.error(`Update failed for ${this.url}: ${(error as Error).message}`)
129-
}
130-
125+
await this.atomicClone()
131126
this.logger.verbose(`Updated ${this.url}!`)
132127
}
133128

packages/umbreld/source/modules/apps/app-store.ts

+25-12
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,34 @@ export default class AppStore {
2727
}
2828

2929
// Initialise repositories
30-
this.logger.log(`Initialising repositories...`)
31-
await pRetry(() => this.update(), {
32-
onFailedAttempt: (error) => {
33-
this.logger.error(
34-
`Attempt ${error.attemptNumber} initialising repositories failed. There are ${error.retriesLeft} retries left.`,
35-
)
36-
},
37-
retries: 5, // This will do exponential backoff for 1s, 2s, 4s, 8s, 16s
38-
})
39-
await this.update()
40-
this.logger.log(`Repositories initialised!`)
30+
this.logger.log(`Initialising default repository...`)
31+
try {
32+
const repositories = await this.getRepositories()
33+
const defaultRepository = repositories.find((repository) => repository.url === this.defaultAppStoreRepo)
34+
if (!defaultRepository) throw new Error(`Default repository ${this.defaultAppStoreRepo} not found`)
35+
await pRetry(
36+
async () => {
37+
await defaultRepository.update()
38+
},
39+
{
40+
onFailedAttempt: (error) => {
41+
this.logger.error(
42+
`Failed to initialise default repository ${defaultRepository.url}: ${
43+
(error as Error).message
44+
}, will retry ${error.retriesLeft} more times.`,
45+
)
46+
},
47+
retries: 5, // This will do exponential backoff for 1s, 2s, 4s, 8s, 16s
48+
},
49+
)
50+
this.logger.log(`Default repository initialised!`)
51+
} catch (error) {
52+
this.logger.error(`Failed to initialise default repository: ${(error as Error).message}`)
53+
}
4154

4255
// Kick off update loop
4356
this.logger.log(`Checking repositories for updates every ${this.updateInterval}`)
44-
this.#stopUpdating = runEvery(this.updateInterval, () => this.update(), {runInstantly: false})
57+
this.#stopUpdating = runEvery(this.updateInterval, () => this.update(), {runInstantly: true})
4558
}
4659

4760
async stop() {

0 commit comments

Comments
 (0)