@camstack/server 1.2.184 → 1.2.186
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3243,13 +3243,23 @@ class AddonRegistryService {
|
|
|
3243
3243
|
// and the real-path match Node's cache keys demand.
|
|
3244
3244
|
//
|
|
3245
3245
|
// The purge mutates the PROCESS-GLOBAL require cache, so purge-then-import
|
|
3246
|
-
// must stay atomic per
|
|
3246
|
+
// must stay atomic per BUNDLE now that the boot plan overlaps (D171):
|
|
3247
3247
|
// `@camstack/addon-remote-storage` ships three addon ids whose entries all
|
|
3248
3248
|
// resolve into one `dist/`, and a sibling's purge landing mid-import would
|
|
3249
|
-
// evict a module graph while it is being evaluated. Different
|
|
3249
|
+
// evict a module graph while it is being evaluated. Different bundles
|
|
3250
3250
|
// still load concurrently.
|
|
3251
|
-
|
|
3252
|
-
|
|
3251
|
+
//
|
|
3252
|
+
// The scope is the BUNDLE (`<addonDir>/dist`), never `dirname(entryPath)`
|
|
3253
|
+
// — see `bundleGraphRootFor`. The narrow scope evicted the entry chunk and
|
|
3254
|
+
// kept the shared chunks, so the re-import re-ran the entry's module-scope
|
|
3255
|
+
// declarations against singletons that had survived, and took the broker
|
|
3256
|
+
// down on 2026-08-29 (D284). The serializer key MUST match the purge
|
|
3257
|
+
// scope: two addon ids of one package now purge the same graph, so
|
|
3258
|
+
// serializing them per entry-folder would let one evict the other's
|
|
3259
|
+
// modules mid-evaluation — the exact race the key exists to prevent.
|
|
3260
|
+
const graphRoot = (0, require_cache_js_1.bundleGraphRootFor)(addonDir, entryPath);
|
|
3261
|
+
const modUnknown = await this.moduleLoadSerializer.run(graphRoot, async () => {
|
|
3262
|
+
(0, require_cache_js_1.purgeRequireCacheUnder)(graphRoot);
|
|
3253
3263
|
// Kept for a genuinely ESM addon entry, where it IS the mechanism.
|
|
3254
3264
|
const cacheBustedUrl = `${(0, node_url_1.pathToFileURL)(entryPath).href}?t=${Date.now()}`;
|
|
3255
3265
|
// A plain `await import()` here is downleveled by tsc (the backend builds
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.purgeRequireCacheUnder = purgeRequireCacheUnder;
|
|
7
|
+
exports.bundleGraphRootFor = bundleGraphRootFor;
|
|
7
8
|
/**
|
|
8
9
|
* require-cache — evicting an addon's own modules so a hot-updated bundle
|
|
9
10
|
* is actually re-read.
|
|
@@ -36,6 +37,10 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
36
37
|
* hub's own modules and every other addon's, turning a catalog refresh into a
|
|
37
38
|
* process-wide reload. Best-effort — a cache that cannot be walked leaves the
|
|
38
39
|
* previous (stale) behaviour rather than failing the caller.
|
|
40
|
+
*
|
|
41
|
+
* **The directory must be the whole BUNDLE, never the entry's own folder** —
|
|
42
|
+
* see {@link bundleGraphRootFor}. A narrower scope purges half a module graph,
|
|
43
|
+
* which is worse than purging none of it.
|
|
39
44
|
*/
|
|
40
45
|
function purgeRequireCacheUnder(dir) {
|
|
41
46
|
try {
|
|
@@ -52,6 +57,39 @@ function purgeRequireCacheUnder(dir) {
|
|
|
52
57
|
// Non-CJS host, or a frozen cache. The caller's import still runs.
|
|
53
58
|
}
|
|
54
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The directory that holds one addon bundle's WHOLE module graph.
|
|
62
|
+
*
|
|
63
|
+
* A multi-entry bundle does not live under its entry's folder. Every addon in
|
|
64
|
+
* this repo builds through `tools/build/vite-lib.preset.ts`, whose entries are
|
|
65
|
+
* `dist/<addon>/index.js` — and whose SHARED CHUNKS (`dist/dist-<hash>.js`,
|
|
66
|
+
* `dist/node-<hash>.js`, …) sit one level up, in `dist/`. Purging
|
|
67
|
+
* `dirname(entryPath)` therefore evicts the entry and leaves the chunks, so the
|
|
68
|
+
* re-import RE-EXECUTES the entry against module state that was never reset.
|
|
69
|
+
*
|
|
70
|
+
* That is not a stale-cache bug, it is a corrupted one, and it took the hub's
|
|
71
|
+
* `stream-broker` down on 2026-08-29: the entry chunk carries
|
|
72
|
+
* `log-channels.ts`'s module-scope `declareLogChannel` calls while the
|
|
73
|
+
* `LogChannelRegistry` singleton they write to is inlined into the shared
|
|
74
|
+
* chunk. Half the graph re-ran, the registry did not, and the second
|
|
75
|
+
* declaration threw `log channel "stream-broker.webrtc" is already declared in
|
|
76
|
+
* this process` — a message that is correct, and that named the loader rather
|
|
77
|
+
* than the addon. `dist/` is the unit the bundler emits, so `dist/` is the unit
|
|
78
|
+
* the cache is purged in.
|
|
79
|
+
*
|
|
80
|
+
* `node_modules/` under the addon is deliberately OUTSIDE this root: a package
|
|
81
|
+
* that declares `camstack.nativeDependencies` installs `.node` bindings there,
|
|
82
|
+
* and re-`dlopen`ing a native addon is not a refresh, it is a coin flip.
|
|
83
|
+
*
|
|
84
|
+
* Falls back to the entry's directory when there is no `dist/` above it (a
|
|
85
|
+
* loose `loadFromPath` module in a test or a dev tree) — the historical
|
|
86
|
+
* behaviour, for the shape that has no bundle.
|
|
87
|
+
*/
|
|
88
|
+
function bundleGraphRootFor(addonDir, entryPath) {
|
|
89
|
+
const distDir = node_path_1.default.resolve(addonDir, 'dist');
|
|
90
|
+
const withSep = distDir.endsWith(node_path_1.default.sep) ? distDir : `${distDir}${node_path_1.default.sep}`;
|
|
91
|
+
return entryPath.startsWith(withSep) ? distDir : node_path_1.default.dirname(entryPath);
|
|
92
|
+
}
|
|
55
93
|
/** The directory as given and as Node sees it, both as trailing-separator prefixes. */
|
|
56
94
|
function candidatePrefixes(dir) {
|
|
57
95
|
const withSep = (d) => (d.endsWith(node_path_1.default.sep) ? d : `${d}${node_path_1.default.sep}`);
|
package/dist/main.js
CHANGED
|
@@ -239,6 +239,15 @@ async function bootstrap() {
|
|
|
239
239
|
// 256KB pages it committed at a sawtooth peak, and an ordinary major GC does not
|
|
240
240
|
// return them. `createV8Reclaimer()` returns undefined if V8 declines, and the
|
|
241
241
|
// heartbeat then behaves exactly as it did before.
|
|
242
|
+
//
|
|
243
|
+
// What it recovers, and what it does NOT: the reclaimer is
|
|
244
|
+
// `gc({ execution: 'sync', flavor: 'last-resort' })` — V8 and only V8. It hands back the
|
|
245
|
+
// 256KB pages V8 committed at a sawtooth peak, which on 2026-08-27 was ~1.3GB of a 4.87GiB
|
|
246
|
+
// process. The other ~2.8GB, spread across 13 anonymous mappings >=64MB, is glibc memory
|
|
247
|
+
// already freed by the allocator and never returned to the kernel; nothing in this repository
|
|
248
|
+
// calls `malloc_trim`, and no V8 flavor reaches it. So the pass is a real bound on the V8
|
|
249
|
+
// share and touches none of the share that grew. It is telemetry plus a partial bound, not a
|
|
250
|
+
// fix — do not read a reclaim line as "the leak was handled".
|
|
242
251
|
const heapReclaimer = (0, system_1.createV8Reclaimer)();
|
|
243
252
|
const heapReclaim = heapReclaimer === undefined ? undefined : { reclaim: heapReclaimer };
|
|
244
253
|
// ...and the budget the heartbeat alarms on. hub-main has no manifest to declare one in, and
|
|
@@ -246,7 +255,14 @@ async function bootstrap() {
|
|
|
246
255
|
// the image never carries this repo's backend. So the number lives in `@camstack/server`,
|
|
247
256
|
// which is what `applyServerUpdate` replaces, for exactly the reason the heartbeat itself is
|
|
248
257
|
// started from this file. See `hubMainRssBudget` for why 4096, and why it is expected to fire.
|
|
249
|
-
|
|
258
|
+
//
|
|
259
|
+
// The sink is DEFERRED. Started here, before any logger exists, the heartbeat could only ever
|
|
260
|
+
// reach `console.log` — which is not a log destination, so for 42 hours Loki carried a `[mem]`
|
|
261
|
+
// line for every runner in the cluster and none for the largest process in it. The sink is
|
|
262
|
+
// repointed at `LoggingService` the moment it exists (below), and boot lines keep going to
|
|
263
|
+
// stdout exactly as before. See `createDeferredHeapWatchSink`.
|
|
264
|
+
const heapWatchSink = (0, system_1.createDeferredHeapWatchSink)(system_1.HUB_MAIN_HEAP_WATCH_LABEL);
|
|
265
|
+
(0, system_1.startHeapWatch)(system_1.HUB_MAIN_HEAP_WATCH_LABEL, heapWatchSink.sink, undefined, heapReclaim, undefined, undefined, true, (0, system_1.hubMainRssBudget)());
|
|
250
266
|
// Clean up orphaned processes from previous crashes before starting
|
|
251
267
|
cleanupOrphanProcesses();
|
|
252
268
|
// SPA fallback — set later when admin UI is resolved, used by addon route catch-all
|
|
@@ -334,6 +350,21 @@ async function bootstrap() {
|
|
|
334
350
|
// If registration fails, start in degraded mode: serve a health warning endpoint.
|
|
335
351
|
// Instantiate new core services
|
|
336
352
|
const loggingService = app.get(logging_service_1.LoggingService);
|
|
353
|
+
// The heap heartbeat's handover: from here on hub-main's `[mem]` lines go through the log
|
|
354
|
+
// manager like every runner's do — buffer, console destination, rotated file and Loki — so
|
|
355
|
+
// the one process that mediates every cross-runner call is finally trendable next to the
|
|
356
|
+
// runners it forked, in the same vocabulary. Destinations that register later (Loki is an
|
|
357
|
+
// addon, so it does) are replayed the ring buffer, so the lines between here and then ship
|
|
358
|
+
// too. Deliberately the FIRST thing done with `loggingService`.
|
|
359
|
+
const heapWatchLogger = loggingService.createLogger('heap-watch');
|
|
360
|
+
heapWatchSink.attach({
|
|
361
|
+
info: (line) => {
|
|
362
|
+
heapWatchLogger.info(line);
|
|
363
|
+
},
|
|
364
|
+
warn: (line) => {
|
|
365
|
+
heapWatchLogger.warn(line);
|
|
366
|
+
},
|
|
367
|
+
});
|
|
337
368
|
const addonRouteRegistry = new system_1.AddonRouteRegistry();
|
|
338
369
|
const dataPlaneRegistry = new system_1.DataPlaneRegistry();
|
|
339
370
|
// Use Fastify-managed notification/toast wrappers (globally provided by NotificationModule)
|