Skip to content

Commit f0c91fa

Browse files
committed
chore: log a failed route-cache clear and spell out the read-only key rollback
The route-cache clear stays non-fatal but warns when it fails for any reason other than a missing build id or cache. The api-key-read-only flag says to revoke or replace read-only keys before rolling back.
1 parent 49ef21a commit f0c91fa

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎apps/sim/lib/core/config/feature-flags.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const FEATURE_FLAGS = {
7979
},
8080
'api-key-read-only': {
8181
description:
82-
'Allow creating read-only API keys. Turn on only after every pod runs a release that enforces key access, since older pods treat a read-only key as full access. Before rolling back below the release that added read-only keys, turn this off first: that older code also serves every existing read-only key as full access. Enforcement of existing read-only keys never depends on this flag. Global; disabled by default.',
82+
'Allow creating read-only API keys. Turn on only after every pod runs a release that enforces key access, since older pods treat a read-only key as full access. Before rolling back below the release that added read-only keys, turn this off and revoke or replace every existing read-only key: turning the flag off only stops new ones, and that older code serves existing read-only keys as full access. Enforcement of existing read-only keys never depends on this flag. Global; disabled by default.',
8383
fallback: 'API_KEY_READ_ONLY',
8484
},
8585
'mothership-model-selector': {

‎apps/sim/lib/core/utils/route-cache.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { readdir, readFile, rm, writeFile } from 'node:fs/promises'
22
import { join } from 'node:path'
3+
import { createLogger } from '@sim/logger'
4+
import { getErrorMessage } from '@sim/utils/errors'
5+
6+
const logger = createLogger('RouteCache')
37

48
const BUILD_MARKER = '.build-id'
59

610
/**
711
* Clears Next's route cache when it was written by a different build. Its keys carry no build
812
* id, and the image declares the directory a volume, so a container recreated from a newer
913
* image would otherwise serve pages the old build rendered, pointing at chunks it no longer
10-
* ships. Never throws: a cache that cannot be read or cleared is left to Next.
14+
* ships. Never throws: a cache that cannot be read or cleared is left to Next, with a warning
15+
* unless there was simply no build id or cache to read.
1116
*/
1217
export async function clearRouteCacheFromOtherBuild(nextDirectory: string): Promise<void> {
1318
const routeCache = join(nextDirectory, 'server', 'route-cache')
@@ -21,5 +26,10 @@ export async function clearRouteCacheFromOtherBuild(nextDirectory: string): Prom
2126
entries.map((entry) => rm(join(routeCache, entry), { recursive: true, force: true }))
2227
)
2328
await writeFile(join(routeCache, BUILD_MARKER), buildId)
24-
} catch {}
29+
} catch (error) {
30+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return
31+
logger.warn('Could not clear the route cache from an earlier build', {
32+
error: getErrorMessage(error),
33+
})
34+
}
2535
}

0 commit comments

Comments
 (0)