@rightkit/release 0.6.62 → 0.6.63
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/package.json +1 -1
- package/rightkit-versions.json +1 -1
- package/snapshot.mjs +29 -2
package/package.json
CHANGED
package/rightkit-versions.json
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@rightkit/qa": "0.7.0",
|
|
50
50
|
"@rightkit/qa-chrome": "0.1.12",
|
|
51
51
|
"@rightkit/react-shell": "0.7.6",
|
|
52
|
-
"@rightkit/release": "0.6.
|
|
52
|
+
"@rightkit/release": "0.6.63",
|
|
53
53
|
"@rightkit/send-ui": "0.1.0",
|
|
54
54
|
"@rightkit/settings-ui": "0.7.5",
|
|
55
55
|
"@rightkit/social-ui": "0.2.1",
|
package/snapshot.mjs
CHANGED
|
@@ -807,6 +807,12 @@ export const windowsSelfCheckScript = (name) => [
|
|
|
807
807
|
"$in = $false; if (-not [RkJob]::IsProcessInJob([RkJob]::GetCurrentProcess(), $j, [ref]$in)) { 'ERR:' + [Runtime.InteropServices.Marshal]::GetLastWin32Error(); exit 0 }",
|
|
808
808
|
"if ($in) { 'IN' } else { 'OUT' }",
|
|
809
809
|
].join("\n");
|
|
810
|
+
/** Asks Windows itself about a named job, with no holder: `GONE:<error>` when no such job exists any more, else `ACTIVE:<count>`. */
|
|
811
|
+
export const windowsJobProbeScript = (name) => [
|
|
812
|
+
"$ErrorActionPreference = 'Stop'", JOB_TYPE,
|
|
813
|
+
`$j = [RkJob]::OpenJobObjectW(0x0004, $false, ${psString(name)}); if ($j -eq [IntPtr]::Zero) { 'GONE:' + [Runtime.InteropServices.Marshal]::GetLastWin32Error(); exit 0 }`,
|
|
814
|
+
"'ACTIVE:' + [RkJob]::Active($j)",
|
|
815
|
+
].join("\n");
|
|
810
816
|
const readJson = (file) => { try { return JSON.parse(fs.readFileSync(file, "utf8").replace(/^/, "")); } catch { return null; } };
|
|
811
817
|
const sleepMs = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
812
818
|
/** The real Windows operations; tests pass their own. */
|
|
@@ -820,6 +826,18 @@ export const windowsJobOps = {
|
|
|
820
826
|
if (r.error || r.status !== 0 || !/^(IN|OUT)$/m.test(out)) throw new Error(`the containment self-check gave no answer (${r.error?.message ?? out.slice(0, 120)})`);
|
|
821
827
|
return /^IN$/m.test(out) ? "IN" : "OUT";
|
|
822
828
|
},
|
|
829
|
+
/**
|
|
830
|
+
* The named job as Windows shows it, asked without its holder: `{ exists: false }` when Windows has no job of that name (a job with no open handle
|
|
831
|
+
* and no process in it is deleted by Windows, so every process of it has ended), else `{ exists: true, active }`. Throws when Windows gave no answer.
|
|
832
|
+
*/
|
|
833
|
+
jobActive(name) {
|
|
834
|
+
const r = spawnSync("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(windowsJobProbeScript(name), "utf16le").toString("base64")], { encoding: "utf8", timeout: 60_000, windowsHide: true });
|
|
835
|
+
const out = String(r.stdout ?? "").trim(); const gone = /^GONE:(\d+)$/m.exec(out); const active = /^ACTIVE:(\d+)$/m.exec(out);
|
|
836
|
+
if (r.error || r.status !== 0 || (!gone && !active)) throw new Error(`Windows gave no answer about the job (${r.error?.message ?? out.slice(0, 120)})`);
|
|
837
|
+
// 2 is ERROR_FILE_NOT_FOUND: no object of that name. Any other failure to open it (access denied, ...) proves nothing.
|
|
838
|
+
if (gone) { if (Number(gone[1]) !== 2) throw new Error(`the job could not be opened (Windows error ${gone[1]})`); return { exists: false }; }
|
|
839
|
+
return { exists: true, active: Number(active[1]) };
|
|
840
|
+
},
|
|
823
841
|
sleep: sleepMs,
|
|
824
842
|
/** The host's last boot as Unix ms (the deleted build-ownership.mjs read it the same way: [DateTimeOffset] of LastBootUpTime, never local-time arithmetic). */
|
|
825
843
|
bootTime() {
|
|
@@ -888,7 +906,7 @@ export function queryJobHolder(file, { job, timeoutMs = 5000, sleep = sleepMs }
|
|
|
888
906
|
* A record that is not contained proves nothing, at the holder's own release or after it died: live (acquisition refuses a self-check OUT, so only a damaged record says so).
|
|
889
907
|
* A dead holder's job made before the host's last boot is gone (the reboot ended it); a holder killed without a reboot leaves the lock busy (fail closed).
|
|
890
908
|
*/
|
|
891
|
-
export function windowsJobLive(lockFile, { self = 0, query = queryJobHolder, bootTime = () => windowsJobOps.bootTime() } = {}) {
|
|
909
|
+
export function windowsJobLive(lockFile, { self = 0, query = queryJobHolder, bootTime = () => windowsJobOps.bootTime(), probe = (name) => windowsJobOps.jobActive(name) } = {}) {
|
|
892
910
|
let record = null;
|
|
893
911
|
try { record = JSON.parse(fs.readFileSync(jobRecordOf(lockFile), "utf8")); } catch (e) { if (e?.code === "ENOENT") return []; return [`job record unreadable (${e?.code ?? e?.message})`]; }
|
|
894
912
|
if (record?.schema !== WINDOWS_JOB_SCHEMA || typeof record.job !== "string" || typeof record.holder !== "string" || !HOLDER_NAME.test(record.holder)) return ["job record malformed"];
|
|
@@ -903,7 +921,16 @@ export function windowsJobLive(lockFile, { self = 0, query = queryJobHolder, boo
|
|
|
903
921
|
const state = readJson(file);
|
|
904
922
|
if (state?.schema === WINDOWS_JOB_SCHEMA && state.job === record.job && state.state === "drained") return [];
|
|
905
923
|
try { const { active } = query(file, { job: record.job }); return active - self > 0 ? [`job ${record.job} (${active - self} process(es))`] : []; }
|
|
906
|
-
catch (e) {
|
|
924
|
+
catch (e) {
|
|
925
|
+
// The holder did not answer. For a dead lock holder that is what a holder killed with its gate looks like (GC-A27 NN12: the next ordinary run must start
|
|
926
|
+
// by itself), so Windows is asked directly: no job of that name left, or a job with no process in it, proves every process of it has ended. Anything
|
|
927
|
+
// Windows cannot say stays unknown, which counts as live. A holder asking about its own job (self > 0) never takes this path.
|
|
928
|
+
if (self === 0) {
|
|
929
|
+
try { const seen = probe(record.job); if (!seen.exists || seen.active === 0) return []; return [`job ${record.job} (${seen.active} process(es); its holder is gone)`]; }
|
|
930
|
+
catch (p) { return [`job ${record.job} unknown (${e.message}; ${p.message})`]; }
|
|
931
|
+
}
|
|
932
|
+
return [`job ${record.job} unknown (${e.message})`];
|
|
933
|
+
}
|
|
907
934
|
}
|
|
908
935
|
|
|
909
936
|
/** The recorded process groups of `lockFile` that still answer (kill(-group, 0) is not ESRCH); a group that cannot be judged counts as alive.
|