@smoothbricks/nx-plugin 0.5.2 → 0.5.3
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.
- package/README.md +19 -2
- package/dist/cargo-source-hash.d.ts +2 -2
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +106 -46
- package/managed/raw/patches/nx@23.2.1.patch +182 -45
- package/package.json +1 -1
- package/src/cargo-source-hash.test.ts +143 -2
- package/src/cargo-source-hash.ts +108 -44
- package/src/nx-daemon-start-never.test.ts +126 -0
- package/src/nx-task-output-lease.test.ts +136 -0
- package/test-timings.json +92 -91
package/README.md
CHANGED
|
@@ -426,8 +426,25 @@ toolchain pins, wrapper scripts, N-API configuration and CLI version.
|
|
|
426
426
|
Runtime file identities are rooted in Cargo package name/version and the declared input role, not in the consuming
|
|
427
427
|
checkout's absolute path or depth. Source paths are package-relative; compiled-in data keeps its declaring source and
|
|
428
428
|
literal path as its identity. Identical main/shed inputs therefore share a key, while changed bytes, module names and
|
|
429
|
-
symlink targets still move it.
|
|
430
|
-
resolution memo schema retains package names/versions;
|
|
429
|
+
symlink targets still move it. File identities retain their globally sorted `cargo-path-inputs-v2` transcript, including
|
|
430
|
+
the original insertion order for equal identities. The Cargo resolution memo schema retains package names/versions;
|
|
431
|
+
refreshing that memo does not reset the Nx task database.
|
|
432
|
+
|
|
433
|
+
Runtime include discovery is a bounded fuse, not a source-byte cache. Ordinary scheduled Rust sources are read once:
|
|
434
|
+
their buffer supplies both the existing literal scanner and SHA-256. `file` identities precede the same package's
|
|
435
|
+
`include` identities; packages sharing an identity are processed together. An earlier package's include can consume a
|
|
436
|
+
later package's source, but only its discovered references survive until that later identity's boundary. Retention is
|
|
437
|
+
one live file buffer plus the current UTF-8 decode/tokens and path metadata, including across package boundaries.
|
|
438
|
+
Literal spellings are copied into path-sized storage with the same UTF-8 encoding, without Unicode normalization, so
|
|
439
|
+
substring views cannot pin decoded source files.
|
|
440
|
+
|
|
441
|
+
Discovery still scans ignored sources, just as the graph scanner does. Discovery-only sources that are later included
|
|
442
|
+
(for example through an unignored symlink that resolves to an ignored `.rs`) are read twice: serving those from one read
|
|
443
|
+
would require retaining bytes across their discovery and sorted hash positions. This exception preserves the old digest
|
|
444
|
+
rather than introducing a workspace-sized cache. No source bytes or runtime discovery memo survive an invocation.
|
|
445
|
+
Read-count, timing, corpus-equivalence and retention evidence is recorded in
|
|
446
|
+
`benchmarks/cargo-source-read.results.json`; `benchmarks/cargo-source-read.bench.ts` measures real filesystem reads in a
|
|
447
|
+
Node bundle (Bun does not refresh named builtin imports when the benchmark installs its read observers).
|
|
431
448
|
|
|
432
449
|
Members the file index cannot hold, outside the Nx workspace or under `node_modules`, are hashed by one runtime
|
|
433
450
|
`smoo-nx-cargo-hash --closure <projectRoot> <Cargo.toml>` entry, present only while such members exist. Its cached
|
|
@@ -83,8 +83,8 @@ export interface CompiledCargoInput {
|
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Existing literal include_str!/include_bytes! files read by this package's Rust sources.
|
|
86
|
-
* One graph owns the memo; runtime
|
|
87
|
-
* sources separately. Computed paths
|
|
86
|
+
* One graph owns the memo; runtime hashing consumes the same discovery alongside source
|
|
87
|
+
* bytes. Nested packages own their sources separately. Computed paths remain explicit inputs.
|
|
88
88
|
*/
|
|
89
89
|
export declare function compiledInFiles(root: string, cache: Map<string, CompiledCargoInput[]>): CompiledCargoInput[];
|
|
90
90
|
//# sourceMappingURL=cargo-source-hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"AAqFA,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAC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-697,6 +697,7 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
697
697
|
const inputKey = (pkg, role, path) => JSON.stringify([pkg.name, pkg.version, role, path.split(sep).join('/')]);
|
|
698
698
|
const directories = new Map();
|
|
699
699
|
const files = new Map();
|
|
700
|
+
const compareInputs = (left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : left.order - right.order;
|
|
700
701
|
const ancestors = new Set();
|
|
701
702
|
const links = new Map();
|
|
702
703
|
const packageSources = [];
|
|
@@ -704,8 +705,12 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
704
705
|
// deterministic without using a consuming checkout's mount path as an input.
|
|
705
706
|
const includeFile = (file, key) => {
|
|
706
707
|
const prior = files.get(file);
|
|
707
|
-
if (prior
|
|
708
|
-
|
|
708
|
+
if (prior !== undefined && key >= prior.key)
|
|
709
|
+
return undefined;
|
|
710
|
+
// Rekeying must retain the old Map insertion order for equal v2 identities.
|
|
711
|
+
const input = { file, key, order: prior?.order ?? files.size };
|
|
712
|
+
files.set(file, input);
|
|
713
|
+
return input;
|
|
709
714
|
};
|
|
710
715
|
const packages = [...cargo.local].sort((left, right) => left.name < right.name
|
|
711
716
|
? -1
|
|
@@ -782,14 +787,21 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
782
787
|
}
|
|
783
788
|
for (const [directory, owner] of directories)
|
|
784
789
|
await walk(directory, owner, '');
|
|
785
|
-
const
|
|
790
|
+
const scans = new Map();
|
|
791
|
+
const groups = new Map();
|
|
786
792
|
for (const [directory, owner] of directories) {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
793
|
+
const scan = { directory, owner, sources: [...compiledSourceFiles(directory)], found: new Map() };
|
|
794
|
+
for (const source of scan.sources)
|
|
795
|
+
scans.set(source, scan);
|
|
796
|
+
// Equal package identities can interleave, so their discovery shares one boundary.
|
|
797
|
+
const prefix = JSON.stringify([owner.name, owner.version]).slice(0, -1) + ',';
|
|
798
|
+
const group = groups.get(prefix);
|
|
799
|
+
if (group === undefined)
|
|
800
|
+
groups.set(prefix, [scan]);
|
|
801
|
+
else
|
|
802
|
+
group.push(scan);
|
|
792
803
|
}
|
|
804
|
+
const scheduled = [...files.values()].sort(compareInputs);
|
|
793
805
|
const hash = createHash('sha256');
|
|
794
806
|
hash.update('cargo-path-inputs-v2\0');
|
|
795
807
|
for (const { key, target } of [...links.values()].sort((left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : 0)) {
|
|
@@ -798,14 +810,54 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
798
810
|
hash.update(target);
|
|
799
811
|
hash.update('\0');
|
|
800
812
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
813
|
+
async function consume(input) {
|
|
814
|
+
if (files.get(input.file) !== input)
|
|
815
|
+
return;
|
|
816
|
+
const bytes = await readFile(input.file);
|
|
817
|
+
const scan = scans.get(input.file);
|
|
818
|
+
if (scan !== undefined) {
|
|
819
|
+
scans.delete(input.file);
|
|
820
|
+
collectCompiledInputs(input.file, bytes.toString('utf8'), scan.found);
|
|
821
|
+
}
|
|
822
|
+
hash.update(input.key);
|
|
804
823
|
hash.update('\0');
|
|
805
824
|
hash.update(String(bytes.length));
|
|
806
825
|
hash.update('\0');
|
|
807
826
|
hash.update(bytes);
|
|
808
827
|
}
|
|
828
|
+
let next = 0;
|
|
829
|
+
for (const [prefix, group] of [...groups].sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))) {
|
|
830
|
+
// All ordinary sources have a file identity before this package's include identities.
|
|
831
|
+
// Earlier includes may already have consumed a later package's source; only its
|
|
832
|
+
// discovered references survive that boundary, never the source buffer.
|
|
833
|
+
const boundary = prefix + '"include",';
|
|
834
|
+
while (next < scheduled.length && scheduled[next].key < boundary)
|
|
835
|
+
await consume(scheduled[next++]);
|
|
836
|
+
const included = [];
|
|
837
|
+
for (const scan of group) {
|
|
838
|
+
for (const source of scan.sources) {
|
|
839
|
+
if (!scans.delete(source))
|
|
840
|
+
continue;
|
|
841
|
+
// Discovery also visits ignored sources. They have no scheduled identity;
|
|
842
|
+
// if an include alias later names one, preserve the old read-then-hash path.
|
|
843
|
+
collectCompiledInputs(source, readFileSync(source, 'utf8'), scan.found);
|
|
844
|
+
}
|
|
845
|
+
for (const input of [...scan.found.values()].sort((left, right) => left.file < right.file ? -1 : left.file > right.file ? 1 : 0)) {
|
|
846
|
+
if (ignored(input.file))
|
|
847
|
+
continue;
|
|
848
|
+
const accepted = includeFile(await realpath(input.file), inputKey(scan.owner, 'include', relative(scan.directory, input.source) + '\0' + input.literal));
|
|
849
|
+
if (accepted !== undefined)
|
|
850
|
+
included.push(accepted);
|
|
851
|
+
}
|
|
852
|
+
scan.found.clear();
|
|
853
|
+
}
|
|
854
|
+
for (const input of included.sort(compareInputs))
|
|
855
|
+
await consume(input);
|
|
856
|
+
while (next < scheduled.length && scheduled[next].key.startsWith(prefix))
|
|
857
|
+
await consume(scheduled[next++]);
|
|
858
|
+
}
|
|
859
|
+
while (next < scheduled.length)
|
|
860
|
+
await consume(scheduled[next++]);
|
|
809
861
|
return hash.digest('hex');
|
|
810
862
|
}
|
|
811
863
|
/**
|
|
@@ -929,16 +981,7 @@ function gitRepository(directory) {
|
|
|
929
981
|
const INCLUDE_CLOSERS = { '(': ')', '[': ']', '{': '}' };
|
|
930
982
|
const INCLUDE_STRING = /^"([^"\\\r\n]*)"$/u;
|
|
931
983
|
const INCLUDE_RAW_STRING = /^r(#*)"([\s\S]*)"\1$/u;
|
|
932
|
-
|
|
933
|
-
* Existing literal include_str!/include_bytes! files read by this package's Rust sources.
|
|
934
|
-
* One graph owns the memo; runtime hashes use a fresh memo. Nested packages own their
|
|
935
|
-
* sources separately. Computed paths and arbitrary build-script reads remain explicit inputs.
|
|
936
|
-
*/
|
|
937
|
-
export function compiledInFiles(root, cache) {
|
|
938
|
-
const cached = cache.get(root);
|
|
939
|
-
if (cached !== undefined)
|
|
940
|
-
return cached;
|
|
941
|
-
const found = new Map();
|
|
984
|
+
function* compiledSourceFiles(root) {
|
|
942
985
|
const skipped = HASH_SKIPPED_DIRECTORIES;
|
|
943
986
|
const scan = [root];
|
|
944
987
|
while (scan.length > 0) {
|
|
@@ -952,34 +995,51 @@ export function compiledInFiles(root, cache) {
|
|
|
952
995
|
scan.push(child);
|
|
953
996
|
}
|
|
954
997
|
else if (entry.isFile() && entry.name.endsWith('.rs')) {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
998
|
+
yield child;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
function collectCompiledInputs(source, text, found) {
|
|
1004
|
+
if (!text.includes('include_'))
|
|
1005
|
+
return;
|
|
1006
|
+
const tokens = rustTokens(text);
|
|
1007
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
1008
|
+
if (tokens[index]?.text !== 'include_str' && tokens[index]?.text !== 'include_bytes')
|
|
1009
|
+
continue;
|
|
1010
|
+
if (tokens[index + 1]?.text !== '!')
|
|
1011
|
+
continue;
|
|
1012
|
+
const closing = INCLUDE_CLOSERS[tokens[index + 2]?.text ?? ''];
|
|
1013
|
+
const end = tokens[index + 4]?.text === ',' ? index + 5 : index + 4;
|
|
1014
|
+
if (closing === undefined || tokens[end]?.text !== closing)
|
|
1015
|
+
continue;
|
|
1016
|
+
// Own the spelling before matching: captures (and RegExp's last-match state)
|
|
1017
|
+
// must reference path-sized storage, not a view into the decoded source.
|
|
1018
|
+
const literal = Buffer.from(tokens[index + 3]?.text ?? '', 'utf8').toString('utf8');
|
|
1019
|
+
const path = INCLUDE_STRING.exec(literal)?.[1] ?? INCLUDE_RAW_STRING.exec(literal)?.[2];
|
|
1020
|
+
if (path === undefined || path === '')
|
|
1021
|
+
continue;
|
|
1022
|
+
const file = resolve(dirname(source), path);
|
|
1023
|
+
if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
|
|
1024
|
+
const prior = found.get(file);
|
|
1025
|
+
if (prior === undefined || source < prior.source || (source === prior.source && path < prior.literal)) {
|
|
1026
|
+
found.set(file, { file, source, literal: path });
|
|
980
1027
|
}
|
|
981
1028
|
}
|
|
982
1029
|
}
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Existing literal include_str!/include_bytes! files read by this package's Rust sources.
|
|
1033
|
+
* One graph owns the memo; runtime hashing consumes the same discovery alongside source
|
|
1034
|
+
* bytes. Nested packages own their sources separately. Computed paths remain explicit inputs.
|
|
1035
|
+
*/
|
|
1036
|
+
export function compiledInFiles(root, cache) {
|
|
1037
|
+
const cached = cache.get(root);
|
|
1038
|
+
if (cached !== undefined)
|
|
1039
|
+
return cached;
|
|
1040
|
+
const found = new Map();
|
|
1041
|
+
for (const source of compiledSourceFiles(root))
|
|
1042
|
+
collectCompiledInputs(source, readFileSync(source, 'utf8'), found);
|
|
983
1043
|
const files = [...found.values()].sort((left, right) => left.file < right.file ? -1 : left.file > right.file ? 1 : 0);
|
|
984
1044
|
cache.set(root, files);
|
|
985
1045
|
return files;
|
|
@@ -343,7 +343,7 @@ index 9bd7b61bf9ad94c72a198dfe6f15fbcb68dfaac3..c552b4b252c2d0496312ddb6ff481699
|
|
|
343
343
|
flushSyncGeneratorChangesToDisk(generators: string[]): Promise<FlushSyncGeneratorChangesResult>;
|
|
344
344
|
getRegisteredSyncGenerators(): Promise<{
|
|
345
345
|
diff --git a/dist/src/daemon/client/client.js b/dist/src/daemon/client/client.js
|
|
346
|
-
index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..
|
|
346
|
+
index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..a1aeb1ac56800af773219df4f55ee95e324f1a26 100644
|
|
347
347
|
--- a/dist/src/daemon/client/client.js
|
|
348
348
|
+++ b/dist/src/daemon/client/client.js
|
|
349
349
|
@@ -40,7 +40,6 @@ const nx_console_1 = require("../message-types/nx-console");
|
|
@@ -354,7 +354,23 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
|
|
|
354
354
|
const update_workspace_context_1 = require("../message-types/update-workspace-context");
|
|
355
355
|
const tmp_dir_1 = require("../tmp-dir");
|
|
356
356
|
const sandbox_socket_hint_1 = require("../sandbox-socket-hint");
|
|
357
|
-
@@ -
|
|
357
|
+
@@ -135,6 +134,15 @@ class DaemonClient {
|
|
358
|
+
});
|
|
359
|
+
this._enabled = false;
|
|
360
|
+
}
|
|
361
|
+
+ else if (process.env.NX_DAEMON_START === 'never' && !recordedDaemonRuns()) {
|
|
362
|
+
+ // A client that may never start a daemon (every cowshed job's) and
|
|
363
|
+
+ // finds none running computes this command in its own process. A
|
|
364
|
+
+ // daemon it started would serve every client of the checkout through
|
|
365
|
+
+ // the shared record while belonging to this client's job, and end
|
|
366
|
+
+ // with it.
|
|
367
|
+
+ logger_1.clientLogger.log(`[Client] NX_DAEMON_START=never and the recorded daemon is not running: running without the daemon`);
|
|
368
|
+
+ this._enabled = false;
|
|
369
|
+
+ }
|
|
370
|
+
else {
|
|
371
|
+
this._enabled = true;
|
|
372
|
+
}
|
|
373
|
+
@@ -668,27 +676,6 @@ class DaemonClient {
|
|
358
374
|
};
|
|
359
375
|
return this.sendToDaemonViaQueue(message);
|
|
360
376
|
}
|
|
@@ -382,7 +398,33 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
|
|
|
382
398
|
getSyncGeneratorChanges(generators) {
|
|
383
399
|
const message = {
|
|
384
400
|
type: get_sync_generator_changes_1.GET_SYNC_GENERATOR_CHANGES,
|
|
385
|
-
@@ -
|
|
401
|
+
@@ -813,8 +800,23 @@ class DaemonClient {
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (!probe.available) {
|
|
405
|
+
- // Carried as a value so no other caller's probe can substitute for it.
|
|
406
|
+
- daemonPid = await this.startInBackground(probe.refusal);
|
|
407
|
+
+ if (process.env.NX_DAEMON_START === 'never') {
|
|
408
|
+
+ // The daemon enabled() found running has stopped since. Its
|
|
409
|
+
+ // successor is its starter's (cowshed's keeper) to start, never
|
|
410
|
+
+ // this client's. The stop belongs to that owner, not to the
|
|
411
|
+
+ // workspace, so the daemon is off for this process alone: no
|
|
412
|
+
+ // marker that an ordinary terminal would inherit.
|
|
413
|
+
+ const reason = 'The Nx daemon this client was using stopped, and NX_DAEMON_START=never: this client never starts a daemon.';
|
|
414
|
+
+ (0, tmp_dir_1.disableDaemonForThisProcess)(reason);
|
|
415
|
+
+ this._daemonStatus = DaemonStatus.DISCONNECTED;
|
|
416
|
+
+ const error = new Error(reason);
|
|
417
|
+
+ error.daemonStartForbidden = true;
|
|
418
|
+
+ throw error;
|
|
419
|
+
+ }
|
|
420
|
+
+ else {
|
|
421
|
+
+ // Carried as a value so no other caller's probe can substitute for it.
|
|
422
|
+
+ daemonPid = await this.startInBackground(probe.refusal);
|
|
423
|
+
+ }
|
|
424
|
+
}
|
|
425
|
+
this.setUpConnection();
|
|
426
|
+
this._daemonStatus = DaemonStatus.CONNECTED;
|
|
427
|
+
@@ -831,13 +833,24 @@ class DaemonClient {
|
|
386
428
|
}
|
|
387
429
|
}
|
|
388
430
|
async sendToDaemonViaQueue(messageToDaemon, parser) {
|
|
@@ -414,7 +456,7 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
|
|
|
414
456
|
}
|
|
415
457
|
setUpConnection() {
|
|
416
458
|
const socketPath = this.getSocketPath();
|
|
417
|
-
@@ -846,7 +
|
|
459
|
+
@@ -846,7 +859,13 @@ class DaemonClient {
|
|
418
460
|
// sendMessageToDaemon method uses a keep-alive setTimeout to
|
|
419
461
|
// explicitly hold the event loop open while awaiting a response.
|
|
420
462
|
socket.unref();
|
|
@@ -429,7 +471,7 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
|
|
|
429
471
|
// it's ok for the daemon to terminate if the client doesn't wait on
|
|
430
472
|
// any messages from the daemon
|
|
431
473
|
if (this.queue.isEmpty()) {
|
|
432
|
-
@@ -1132,8 +
|
|
474
|
+
@@ -1132,8 +1151,11 @@ class DaemonClient {
|
|
433
475
|
*/
|
|
434
476
|
const { available, refusal: polled } = await this.waitForServerToBeAvailable({ ignoreVersionMismatch: true });
|
|
435
477
|
if (available) {
|
|
@@ -443,6 +485,33 @@ index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..31fcb14fbf3811f0e1c545791026e5a6
|
|
|
443
485
|
}
|
|
444
486
|
else {
|
|
445
487
|
// A permission refusal from either source wins, then the poll's errno,
|
|
488
|
+
@@ -1200,6 +1222,26 @@ function isDocker() {
|
|
489
|
+
function nxJsonIsNotPresent() {
|
|
490
|
+
return !(0, nx_json_1.hasNxJson)(workspace_root_1.workspaceRoot);
|
|
491
|
+
}
|
|
492
|
+
+/**
|
|
493
|
+
+ * Whether the process the daemon record names still runs. Read only under
|
|
494
|
+
+ * NX_DAEMON_START=never, before any request, to choose between that daemon and
|
|
495
|
+
+ * none: a record whose daemon has gone is a reason to run without one, never to
|
|
496
|
+
+ * start one.
|
|
497
|
+
+ */
|
|
498
|
+
+function recordedDaemonRuns() {
|
|
499
|
+
+ const pid = (0, cache_1.getDaemonProcessIdSync)();
|
|
500
|
+
+ if (!Number.isInteger(pid) || pid < 1) {
|
|
501
|
+
+ return false;
|
|
502
|
+
+ }
|
|
503
|
+
+ try {
|
|
504
|
+
+ process.kill(pid, 0);
|
|
505
|
+
+ return true;
|
|
506
|
+
+ }
|
|
507
|
+
+ catch (err) {
|
|
508
|
+
+ // EPERM: a process this one may not signal holds the pid, so it runs.
|
|
509
|
+
+ return err.code === 'EPERM';
|
|
510
|
+
+ }
|
|
511
|
+
+}
|
|
512
|
+
/**
|
|
513
|
+
* The operating system refused the connection. Most often the socket belongs to
|
|
514
|
+
* another user, which is the guarantee the owner-only socket directory buys —
|
|
446
515
|
diff --git a/dist/src/daemon/message-types/daemon-message.d.ts b/dist/src/daemon/message-types/daemon-message.d.ts
|
|
447
516
|
index 9dd6123ad6d9adb20a07f7db56fc476be78cbcca..0b1ee217729d63a29806cf6c38d0fc5d4a2161a5 100644
|
|
448
517
|
--- a/dist/src/daemon/message-types/daemon-message.d.ts
|
|
@@ -2121,7 +2190,7 @@ index 3659fdd1955d56e60cc0158d19ac55d59916d78e..92e6700adfc52a380b3e9e37b655fbc9
|
|
|
2121
2190
|
/**
|
|
2122
2191
|
* Returns the current session count for a phase. Useful for testing.
|
|
2123
2192
|
diff --git a/dist/src/project-graph/project-graph.js b/dist/src/project-graph/project-graph.js
|
|
2124
|
-
index a23de7d0f27d7bc222ee09f4904f5d236510d01d..
|
|
2193
|
+
index a23de7d0f27d7bc222ee09f4904f5d236510d01d..0d8514be79f2ed03c7cc2410ea0d91f7c885d634 100644
|
|
2125
2194
|
--- a/dist/src/project-graph/project-graph.js
|
|
2126
2195
|
+++ b/dist/src/project-graph/project-graph.js
|
|
2127
2196
|
@@ -149,14 +149,7 @@ function handleProjectGraphError(opts, e) {
|
|
@@ -2140,6 +2209,21 @@ index a23de7d0f27d7bc222ee09f4904f5d236510d01d..247ed0fe9f7a1a1a3d8d91d0d772763e
|
|
|
2140
2209
|
}
|
|
2141
2210
|
else if (typeof e.message === 'string') {
|
|
2142
2211
|
const lines = e.message.split('\n');
|
|
2212
|
+
@@ -356,6 +349,14 @@ async function createProjectGraphAndSourceMapsAsync(opts = {
|
|
2213
|
+
(0, tmp_dir_1.markDaemonAsDisabled)(e.message);
|
|
2214
|
+
return buildProjectGraphAndSourceMapsWithoutDaemon();
|
|
2215
|
+
}
|
|
2216
|
+
+ if (e.daemonStartForbidden) {
|
|
2217
|
+
+ // The daemon stopped under a client that may not start one
|
|
2218
|
+
+ // (NX_DAEMON_START=never). The client already turned the daemon off
|
|
2219
|
+
+ // for this process alone; the command continues without it.
|
|
2220
|
+
+ output_1.output.note({ title: `${e.message} Continuing without the daemon.` });
|
|
2221
|
+
+ client_1.daemonClient.reset();
|
|
2222
|
+
+ return buildProjectGraphAndSourceMapsWithoutDaemon();
|
|
2223
|
+
+ }
|
|
2224
|
+
if (e.daemonPermissionError) {
|
|
2225
|
+
// Deliberately not disabled: unlike the inotify limit above, a socket
|
|
2226
|
+
// owned by someone else stops being there when it is removed or the
|
|
2143
2227
|
diff --git a/dist/src/tasks-runner/cache.d.ts b/dist/src/tasks-runner/cache.d.ts
|
|
2144
2228
|
index 34aa44f81f1df63c5d33e58d8b55d15fcf1d7619..edf41406f465726828fa447bd10d71a49a2ede8a 100644
|
|
2145
2229
|
--- a/dist/src/tasks-runner/cache.d.ts
|
|
@@ -3262,10 +3346,10 @@ index 0000000000000000000000000000000000000000..ab141ad0de874122b363f2fd1894dcbd
|
|
|
3262
3346
|
+}
|
|
3263
3347
|
diff --git a/dist/src/tasks-runner/task-output-lease.js b/dist/src/tasks-runner/task-output-lease.js
|
|
3264
3348
|
new file mode 100644
|
|
3265
|
-
index 0000000000000000000000000000000000000000..
|
|
3349
|
+
index 0000000000000000000000000000000000000000..df3e705647a8a38b28125df16ef0c73472b20df3
|
|
3266
3350
|
--- /dev/null
|
|
3267
3351
|
+++ b/dist/src/tasks-runner/task-output-lease.js
|
|
3268
|
-
@@ -0,0 +1,
|
|
3352
|
+
@@ -0,0 +1,233 @@
|
|
3269
3353
|
+"use strict";
|
|
3270
3354
|
+const { channel } = require("node:diagnostics_channel");
|
|
3271
3355
|
+const { writeFileSync } = require("node:fs");
|
|
@@ -3281,12 +3365,20 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
|
|
|
3281
3365
|
+// lock files are never unlinked or replaced.
|
|
3282
3366
|
+if (process.argv[2] === "--nx-task-output-lease-worker") {
|
|
3283
3367
|
+ let held = [];
|
|
3368
|
+
+ // One FileLock, so one descriptor, per lock file for the helper's life:
|
|
3369
|
+
+ // FileLock has no close, and a fresh one per acquire kept every descriptor
|
|
3370
|
+
+ // until garbage collection.
|
|
3371
|
+
+ const locks = new Map();
|
|
3284
3372
|
+ process.on("disconnect", () => process.exit(0));
|
|
3285
3373
|
+ process.on("message", (message) => {
|
|
3286
3374
|
+ try {
|
|
3287
3375
|
+ if (message.type === "acquire") {
|
|
3288
3376
|
+ for (const path of message.paths) {
|
|
3289
|
-
+
|
|
3377
|
+
+ let lock = locks.get(path);
|
|
3378
|
+
+ if (!lock) {
|
|
3379
|
+
+ lock = new FileLock(path);
|
|
3380
|
+
+ locks.set(path, lock);
|
|
3381
|
+
+ }
|
|
3290
3382
|
+ lock.lock();
|
|
3291
3383
|
+ held.push({ lock, path });
|
|
3292
3384
|
+ writeFileSync(path, JSON.stringify({ pid: process.pid, clientPid: process.ppid, purpose: message.purpose, targets: message.targets }));
|
|
@@ -3312,12 +3404,21 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
|
|
|
3312
3404
|
+ });
|
|
3313
3405
|
+}
|
|
3314
3406
|
+else {
|
|
3407
|
+
+ // The pool's slots. A slot is held by a live helper in `workers`; an acquire
|
|
3408
|
+
+ // that finds none free waits in `waiters` for one of exactly two events:
|
|
3409
|
+
+ // a release hands it the released helper, or a helper leaves the pool
|
|
3410
|
+
+ // (exit, failed spawn, failed send, or an error reply, after which it is
|
|
3411
|
+
+ // killed) and `retire` hands it that helper's slot to fork a successor.
|
|
3412
|
+
+ // Every way a helper can stop serving goes through `retire`, so no waiter
|
|
3413
|
+
+ // waits for a slot nothing will free.
|
|
3315
3414
|
+ class TaskOutputLeases {
|
|
3316
3415
|
+ constructor(parallelism, invocationTracker, purpose) {
|
|
3317
3416
|
+ this.purpose = purpose;
|
|
3318
3417
|
+ this.invocationTracker = invocationTracker;
|
|
3319
3418
|
+ this.parallelism = Math.max(1, parallelism);
|
|
3320
3419
|
+ this.workers = new Set();
|
|
3420
|
+
+ this.children = new Set();
|
|
3421
|
+
+ this.reserved = 0;
|
|
3321
3422
|
+ this.idle = [];
|
|
3322
3423
|
+ this.waiters = [];
|
|
3323
3424
|
+ this.stopping = false;
|
|
@@ -3347,43 +3448,17 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
|
|
|
3347
3448
|
+ const paths = targets.map((target) => join(workspaceDataDirectory, "task-output-leases", `${hashArray([this.purpose, target])}.lock`));
|
|
3348
3449
|
+ events.publish({ phase: "waiting", purpose: this.purpose, targets, paths, pid: process.pid });
|
|
3349
3450
|
+ let entry = this.idle.pop();
|
|
3350
|
-
+ if (!entry && this.workers.size >= this.parallelism) {
|
|
3451
|
+
+ if (!entry && this.workers.size + this.reserved >= this.parallelism) {
|
|
3452
|
+
+ // An entry from a release, or null: a retired helper's slot, reserved for this acquire.
|
|
3351
3453
|
+ entry = await new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
|
|
3454
|
+
+ if (!entry) this.reserved--;
|
|
3455
|
+
+ if (this.stopping) {
|
|
3456
|
+
+ if (entry) this.idle.push(entry);
|
|
3457
|
+
+ throw new Error(`Task output lease acquisition cancelled during runner cleanup: ${targets.join(", ")}`);
|
|
3458
|
+
+ }
|
|
3352
3459
|
+ }
|
|
3353
3460
|
+ if (!entry) {
|
|
3354
|
-
+
|
|
3355
|
-
+ execPath: process.execPath,
|
|
3356
|
-
+ execArgv: [],
|
|
3357
|
-
+ stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
3358
|
-
+ });
|
|
3359
|
-
+ entry = { worker, pending: null, failed: null, phase: "idle", exited: null };
|
|
3360
|
-
+ entry.exited = new Promise((resolve) => worker.once("exit", resolve));
|
|
3361
|
-
+ this.workers.add(entry);
|
|
3362
|
-
+ worker.on("message", (message) => {
|
|
3363
|
-
+ const pending = entry.pending;
|
|
3364
|
-
+ entry.pending = null;
|
|
3365
|
-
+ if (message.type === "error") {
|
|
3366
|
-
+ const error = new Error(`Task output lease for ${entry.targets.join(", ")} at ${entry.paths.join(", ")} failed: ${message.message}`);
|
|
3367
|
-
+ error.stack += `\nCaused by lease helper:\n${message.stack}`;
|
|
3368
|
-
+ entry.failed = error;
|
|
3369
|
-
+ pending?.reject(error);
|
|
3370
|
-
+ }
|
|
3371
|
-
+ else {
|
|
3372
|
-
+ pending?.resolve();
|
|
3373
|
-
+ }
|
|
3374
|
-
+ });
|
|
3375
|
-
+ worker.on("error", (cause) => {
|
|
3376
|
-
+ const error = new Error(`Task output lease helper failed for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`, { cause });
|
|
3377
|
-
+ entry.failed = error;
|
|
3378
|
-
+ entry.pending?.reject(error);
|
|
3379
|
-
+ entry.pending = null;
|
|
3380
|
-
+ });
|
|
3381
|
-
+ worker.on("exit", (code, signal) => {
|
|
3382
|
-
+ entry.failed ??= new Error(`Task output lease worker exited (code ${code}, signal ${signal ?? "none"}) for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`);
|
|
3383
|
-
+ entry.pending?.reject(entry.failed);
|
|
3384
|
-
+ entry.pending = null;
|
|
3385
|
-
+ this.workers.delete(entry);
|
|
3386
|
-
+ });
|
|
3461
|
+
+ entry = this.spawn();
|
|
3387
3462
|
+ }
|
|
3388
3463
|
+ entry.targets = targets;
|
|
3389
3464
|
+ entry.paths = paths;
|
|
@@ -3404,11 +3479,73 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
|
|
|
3404
3479
|
+ else this.idle.push(entry);
|
|
3405
3480
|
+ };
|
|
3406
3481
|
+ }
|
|
3482
|
+
+ spawn() {
|
|
3483
|
+
+ const worker = fork(__filename, ["--nx-task-output-lease-worker"], {
|
|
3484
|
+
+ execPath: process.execPath,
|
|
3485
|
+
+ execArgv: [],
|
|
3486
|
+
+ stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
3487
|
+
+ });
|
|
3488
|
+
+ const exited = Promise.withResolvers();
|
|
3489
|
+
+ const entry = { worker, pending: null, failed: null, retired: false, phase: "idle", exited: exited.promise, targets: [], paths: [] };
|
|
3490
|
+
+ const gone = () => {
|
|
3491
|
+
+ this.children.delete(entry);
|
|
3492
|
+
+ exited.resolve();
|
|
3493
|
+
+ };
|
|
3494
|
+
+ this.workers.add(entry);
|
|
3495
|
+
+ this.children.add(entry);
|
|
3496
|
+
+ worker.on("message", (message) => {
|
|
3497
|
+
+ const pending = entry.pending;
|
|
3498
|
+
+ entry.pending = null;
|
|
3499
|
+
+ if (message.type === "error") {
|
|
3500
|
+
+ // The helper unlocked what it held before replying; it no longer serves.
|
|
3501
|
+
+ const error = new Error(`Task output lease for ${entry.targets.join(", ")} at ${entry.paths.join(", ")} failed: ${message.message}`);
|
|
3502
|
+
+ error.stack += `\nCaused by lease helper:\n${message.stack}`;
|
|
3503
|
+
+ pending?.reject(error);
|
|
3504
|
+
+ this.retire(entry, error);
|
|
3505
|
+
+ }
|
|
3506
|
+
+ else {
|
|
3507
|
+
+ pending?.resolve();
|
|
3508
|
+
+ }
|
|
3509
|
+
+ });
|
|
3510
|
+
+ worker.on("error", (cause) => {
|
|
3511
|
+
+ this.retire(entry, new Error(`Task output lease helper failed for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`, { cause }));
|
|
3512
|
+
+ // A helper that never started emits no exit.
|
|
3513
|
+
+ if (worker.pid === undefined) gone();
|
|
3514
|
+
+ });
|
|
3515
|
+
+ worker.on("exit", (code, signal) => {
|
|
3516
|
+
+ this.retire(entry, new Error(`Task output lease worker exited (code ${code}, signal ${signal ?? "none"}) for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`));
|
|
3517
|
+
+ gone();
|
|
3518
|
+
+ });
|
|
3519
|
+
+ return entry;
|
|
3520
|
+
+ }
|
|
3521
|
+
+ // Takes a helper that no longer serves out of the pool, once: its
|
|
3522
|
+
+ // pending exchange fails with the reason, and its slot goes to the
|
|
3523
|
+
+ // oldest waiter, which forks a successor.
|
|
3524
|
+
+ retire(entry, error) {
|
|
3525
|
+
+ if (entry.retired) return;
|
|
3526
|
+
+ entry.retired = true;
|
|
3527
|
+
+ entry.failed ??= error;
|
|
3528
|
+
+ entry.pending?.reject(entry.failed);
|
|
3529
|
+
+ entry.pending = null;
|
|
3530
|
+
+ // A live helper that stopped serving holds no lease: its error reply unlocked them, or a failed send left
|
|
3531
|
+
+ // it unreachable. Killing it releases whatever the kernel still records.
|
|
3532
|
+
+ entry.worker.kill("SIGKILL");
|
|
3533
|
+
+ this.workers.delete(entry);
|
|
3534
|
+
+ const index = this.idle.indexOf(entry);
|
|
3535
|
+
+ if (index !== -1) this.idle.splice(index, 1);
|
|
3536
|
+
+ const waiter = this.waiters.shift();
|
|
3537
|
+
+ if (waiter) {
|
|
3538
|
+
+ this.reserved++;
|
|
3539
|
+
+ waiter.resolve(null);
|
|
3540
|
+
+ }
|
|
3541
|
+
+ }
|
|
3407
3542
|
+ exchange(entry, message) {
|
|
3408
3543
|
+ if (entry.failed) return Promise.reject(entry.failed);
|
|
3409
3544
|
+ return new Promise((resolve, reject) => {
|
|
3410
3545
|
+ entry.pending = { resolve, reject };
|
|
3411
|
-
+ entry.worker.send(message)
|
|
3546
|
+
+ entry.worker.send(message, (error) => {
|
|
3547
|
+
+ if (error) this.retire(entry, new Error(`Task output lease helper for ${entry.targets.join(", ")} at ${entry.paths.join(", ")} could not be sent ${message.type}`, { cause: error }));
|
|
3548
|
+
+ });
|
|
3412
3549
|
+ });
|
|
3413
3550
|
+ }
|
|
3414
3551
|
+ async withTasks(tasks, action) {
|
|
@@ -3437,7 +3574,7 @@ index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a26
|
|
|
3437
3574
|
+ async close() {
|
|
3438
3575
|
+ await this.cancelPending();
|
|
3439
3576
|
+ this.closed = true;
|
|
3440
|
-
+ await Promise.all([...this.
|
|
3577
|
+
+ await Promise.all([...this.children].map((entry) => {
|
|
3441
3578
|
+ entry.worker.kill("SIGKILL");
|
|
3442
3579
|
+ return entry.exited;
|
|
3443
3580
|
+ }));
|