module: add a read-only mode to the compile cache - #65302
Conversation
|
Review requested:
|
447fb62 to
133e37b
Compare
d57ec48 to
dc597d8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65302 +/- ##
==========================================
- Coverage 90.32% 90.13% -0.19%
==========================================
Files 751 751
Lines 249960 252344 +2384
Branches 47204 47452 +248
==========================================
+ Hits 225774 227448 +1674
- Misses 15564 16193 +629
- Partials 8622 8703 +81
🚀 New features to boost your workflow:
|
Commit Queue failed- Loading data for nodejs/node/pull/65302 ✔ Done loading data for nodejs/node/pull/65302 ----------------------------------- PR info ------------------------------------ Title module: add a read-only mode to the compile cache (#65302) Author Shelley Vohr <shelley.vohr@gmail.com> (@codebytere) Branch codebytere:compile-cache-read-only -> nodejs:main Labels c++, lib / src, commit-queue Commits 1 - module: add a read-only mode to the compile cache Committers 1 - Shelley Vohr <shelley.vohr@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65302 Reviewed-By: James M Snell <jasnell@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/65302 Reviewed-By: James M Snell <jasnell@gmail.com> -------------------------------------------------------------------------------- ℹ This PR was created on Sat, 15 Aug 2026 08:56:32 GMT ✔ Approvals: 1 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/65302#pullrequestreview-4948260342 ✘ This PR needs to wait 91 more hours to land (or 0 minutes if there is one more approval) ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-08-17T03:52:44Z: https://ci.nodejs.org/job/node-test-pull-request/75904/ - Querying data for job/node-test-pull-request/75904/ ✔ Build data downloaded - Querying failures of job/node-test-commit/90633/ ✔ Data downloaded ✘ 1 failure(s) on the last Jenkins CI run -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/32149688331 |
|
@aduh95 PTAL when you have a moment! |
| if (!is_dir) { | ||
| result.message = | ||
| "Cache directory does not exist (read-only): " + cache_dir_with_tag; | ||
| result.status = CompileCacheEnableStatus::FAILED; | ||
| return result; | ||
| } |
There was a problem hiding this comment.
Should this emit a warning?
There was a problem hiding this comment.
i don't think so, for consistency: none of the other FAILED paths here (can't create the directory, not writable) warn either. through module.enableCompileCache() the caller gets { status, message } back and can decide what to do with it, and for NODE_COMPILE_CACHE the existing behavior is an inherited env var never adds output to a program that didn't ask for the cache; NODE_DEBUG_NATIVE=COMPILE_CACHE prints it. happy to add one if you feel strongly, but i'd rather do it for all the FAILED cases at once in a follow-up than special-case read-only.
A compile cache generated ahead of time and shipped inside an application package should only ever be read: the package may be immutable or covered by an integrity check, and a cache directory that appears at run time would be a surprise. Add readOnly to module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1: existing entries are loaded as before, nothing is serialized or persisted, flushCompileCache() is a no-op, and the cache directory is used as found rather than created, so enabling against a missing directory fails instead of making one. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
dc597d8 to
f201d83
Compare
A compile cache generated ahead of time and shipped inside an application package should only ever be read: the package may be immutable (an Electron
app.asar, a read-only image) or covered by an integrity check, and a cache directory that appears at run time next to shipped code is a surprise either way. Today enabling the cache always implies writing: the tag directory is created on enable, and every module without an accepted entry is serialized and persisted at exit or onflushCompileCache().This adds
readOnlytomodule.enableCompileCache()andNODE_COMPILE_CACHE_READONLY=1. With it, existing entries are looked up and loaded exactly as before; nothing is serialized into the in-memory store or written to disk,flushCompileCache()is a no-op, the write-permission check is skipped, and the cache directory is used as found rather than created, so enabling against a directory that does not exist fails (FAILED, with a message) instead of making one.EnableOptionbecomes a small flag set (PORTABLE,READ_ONLY) since the two combine. Docs cover the option, the environment variable (cli.md, node.1) and a short section in module.md;test-compile-cache-api-readonlycovers the missing-directory case, reading a previously generated cache without writing new entries, and the environment variable.Context: same application as #65293 (an Electron app shipping its main-process cache in the package); review there asked that production launches never attempt writes.