mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 04:34:13 +00:00
fix(windows): retry owned runtime cleanup on sharing conflicts
Bound retries of native close conflicts at the retained runtime owner. Preserve exact failures and later retry authority after exhaustion. Attempt all verifier cleanup while retaining primary failures; extend held-file Windows verification. Refs #4136, #4185 Co-authored-by: DeryFerd <deryferdikao125@gmail.com>
This commit is contained in:
1 parent
8d8257928b
commit
0679a7972b
7 files changed
+320
-41
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import { join } from "node:path";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
||||
import { closeVerifierResources } from "./lib/verifier-cleanup.mjs";
|
||||
import { exec, execNpm } from "./lib/verify-package-core.mjs";
|
||||
import { WABT_WORKFLOW_TIMEOUT_MS } from "./lib/wabt-verifier-timeouts.mjs";
|
||||
import { verifyPackagePack } from "./verify-package-pack.mjs";
|
||||
@@ -9,6 +10,7 @@ import { verifyPackagePack } from "./verify-package-pack.mjs";
|
||||
const root = await PrivateRuntimeRoot.create({
|
||||
prefix: "rea-wabt-package-verifier-",
|
||||
});
|
||||
let primaryError;
|
||||
try {
|
||||
const { tarball } = await verifyPackagePack({
|
||||
root: process.cwd(),
|
||||
@@ -56,6 +58,9 @@ try {
|
||||
},
|
||||
);
|
||||
process.stdout.write(verified.stdout);
|
||||
} catch (cause) {
|
||||
primaryError = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
await root.close();
|
||||
await closeVerifierResources([() => root.close()], primaryError);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { closeVerifierResources } from "./lib/verifier-cleanup.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (process.platform !== "linux")
|
||||
@@ -106,6 +107,7 @@ const expectedAddressSpace = Math.min(
|
||||
.map((value) => (value === "unlimited" ? Infinity : Number(value))),
|
||||
);
|
||||
|
||||
let primaryError;
|
||||
try {
|
||||
await writeFile(path, source);
|
||||
await writeFile(bluetooth, bluetoothSource);
|
||||
@@ -463,10 +465,14 @@ try {
|
||||
"network with spaces.pcap",
|
||||
"paged.pcap",
|
||||
]);
|
||||
} catch (cause) {
|
||||
primaryError = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await root.close();
|
||||
await closeVerifierResources(
|
||||
[() => client.close(), () => transport.close(), () => root.close()],
|
||||
primaryError,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
|
||||
@@ -12,6 +12,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { closeVerifierResources } from "./lib/verifier-cleanup.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (process.platform !== "linux")
|
||||
@@ -83,6 +84,7 @@ const expectedAddressSpace = Math.min(
|
||||
.map((value) => (value === "unlimited" ? Infinity : Number(value))),
|
||||
);
|
||||
|
||||
let primaryError;
|
||||
try {
|
||||
await writeFile(path, source);
|
||||
await client.connect(transport);
|
||||
@@ -383,10 +385,14 @@ try {
|
||||
"paged.vcd",
|
||||
"recording with spaces.vcd",
|
||||
]);
|
||||
} catch (cause) {
|
||||
primaryError = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await root.close();
|
||||
await closeVerifierResources(
|
||||
[() => client.close(), () => transport.close(), () => root.close()],
|
||||
primaryError,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
|
||||
@@ -23,6 +23,7 @@ import { pathToFileURL } from "node:url";
|
||||
import { verifyWindowsProtocolInput } from "./lib/windows-protocol-input.mjs";
|
||||
import { verifyWindowsJobMemoryLimit } from "./lib/windows-job-memory-limit.mjs";
|
||||
import { verifyVolumeRootAppendLease } from "./lib/windows-volume-root-append-lease.mjs";
|
||||
import { closeVerifierResources } from "./lib/verifier-cleanup.mjs";
|
||||
|
||||
if (process.platform !== "win32")
|
||||
throw new Error(
|
||||
@@ -66,6 +67,49 @@ const exists = (path) =>
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
const startDeleteSharingDeniedReader = async (path) => {
|
||||
const child = spawn(
|
||||
"powershell.exe",
|
||||
[
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-Command",
|
||||
"$ErrorActionPreference = 'Stop'; " +
|
||||
"$stream = [IO.File]::Open($env:REA_CLEANUP_HELD_PATH, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite); " +
|
||||
"try { [Console]::WriteLine('ready'); [Console]::In.ReadLine() | Out-Null } " +
|
||||
"finally { $stream.Dispose() }",
|
||||
],
|
||||
{
|
||||
env: { ...process.env, REA_CLEANUP_HELD_PATH: path },
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
},
|
||||
);
|
||||
const closed = once(child, "close");
|
||||
void closed.catch(() => undefined);
|
||||
try {
|
||||
const [ready] = await once(child.stdout, "data", {
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
});
|
||||
assert.equal(String(ready).trim(), "ready");
|
||||
} catch (cause) {
|
||||
try {
|
||||
child.kill();
|
||||
await closed;
|
||||
} catch (cleanupCause) {
|
||||
throw new AggregateError(
|
||||
[cause, cleanupCause],
|
||||
"Reader startup and child cleanup failed",
|
||||
{ cause },
|
||||
);
|
||||
}
|
||||
throw cause;
|
||||
}
|
||||
return { child, closed };
|
||||
};
|
||||
const stopDeleteSharingDeniedReader = async ({ child, closed }) => {
|
||||
child.kill();
|
||||
await closed;
|
||||
};
|
||||
const live = (pid) => {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
@@ -516,32 +560,14 @@ process.stdout.write(JSON.stringify({executable:basename(process.execPath),abiVe
|
||||
"cleanup-retry-",
|
||||
);
|
||||
const heldPath = join(retryRuntime.observation.path, "snapshot.bin");
|
||||
await retryRuntime.snapshot(source, "snapshot.bin");
|
||||
const holder = spawn(
|
||||
"powershell.exe",
|
||||
[
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-Command",
|
||||
"$ErrorActionPreference = 'Stop'; " +
|
||||
"$stream = [IO.File]::Open($env:REA_CLEANUP_HELD_PATH, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite); " +
|
||||
"try { [Console]::WriteLine('ready'); [Console]::In.ReadLine() | Out-Null } " +
|
||||
"finally { $stream.Dispose() }",
|
||||
],
|
||||
{
|
||||
env: { ...process.env, REA_CLEANUP_HELD_PATH: heldPath },
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
},
|
||||
);
|
||||
const holderClosed = once(holder, "close");
|
||||
void holderClosed.catch(() => undefined);
|
||||
let holder;
|
||||
let primaryError;
|
||||
try {
|
||||
const [ready] = await once(holder.stdout, "data", {
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
});
|
||||
assert.equal(String(ready).trim(), "ready");
|
||||
await retryRuntime.snapshot(source, "snapshot.bin");
|
||||
holder = await startDeleteSharingDeniedReader(heldPath);
|
||||
// The reader denies delete sharing. Cleanup must retain ownership when
|
||||
// its handle-relative open receives ERROR_SHARING_VIOLATION (32).
|
||||
// its handle-relative open receives ERROR_SHARING_VIOLATION (32) through
|
||||
// the bounded automatic retries; a later explicit close must succeed.
|
||||
await assert.rejects(retryRuntime.close(), { win32Code: 32 });
|
||||
assert.equal(
|
||||
windowsPrivateRuntime(retryRuntime.observation.path),
|
||||
@@ -552,8 +578,8 @@ process.stdout.write(JSON.stringify({executable:basename(process.execPath),abiVe
|
||||
() => retryRuntime.writeFile("after-close.txt", "forbidden"),
|
||||
/cleanup is pending/u,
|
||||
);
|
||||
holder.stdin.end("\n");
|
||||
const [exitCode] = await holderClosed;
|
||||
holder.child.stdin.end("\n");
|
||||
const [exitCode] = await holder.closed;
|
||||
assert.equal(exitCode, 0);
|
||||
await retryRuntime.close();
|
||||
await retryRuntime.close();
|
||||
@@ -563,10 +589,62 @@ process.stdout.write(JSON.stringify({executable:basename(process.execPath),abiVe
|
||||
/No native private runtime/u,
|
||||
);
|
||||
report.controls.cleanupFailureRetainsOwnershipForRetry = true;
|
||||
} catch (cause) {
|
||||
primaryError = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
holder.kill();
|
||||
await holderClosed.catch(() => undefined);
|
||||
await retryRuntime.close();
|
||||
await closeVerifierResources(
|
||||
[
|
||||
...(holder === undefined
|
||||
? []
|
||||
: [() => stopDeleteSharingDeniedReader(holder)]),
|
||||
() => retryRuntime.close(),
|
||||
],
|
||||
primaryError,
|
||||
);
|
||||
}
|
||||
const transientRuntime = WindowsPrivateRuntime.create(
|
||||
workspace,
|
||||
"cleanup-transient-",
|
||||
);
|
||||
const transientHeldPath = join(
|
||||
transientRuntime.observation.path,
|
||||
"snapshot.bin",
|
||||
);
|
||||
let transientHolder;
|
||||
let transientPrimaryError;
|
||||
try {
|
||||
await transientRuntime.snapshot(source, "snapshot.bin");
|
||||
transientHolder = await startDeleteSharingDeniedReader(transientHeldPath);
|
||||
// The first native close is synchronous and must fail while this reader
|
||||
// is held. Releasing it while the owner waits allows its own retry to
|
||||
// complete without the caller issuing another close.
|
||||
const closing = transientRuntime.close();
|
||||
transientHolder.child.stdin.end("\n");
|
||||
const [, [exitCode]] = await Promise.all([
|
||||
closing,
|
||||
transientHolder.closed,
|
||||
]);
|
||||
assert.equal(exitCode, 0);
|
||||
assert.equal(await exists(transientRuntime.observation.path), false);
|
||||
assert.throws(
|
||||
() => windowsPrivateRuntime(transientRuntime.observation.path),
|
||||
/No native private runtime/u,
|
||||
);
|
||||
report.controls.cleanupTransientConflictRetries = true;
|
||||
} catch (cause) {
|
||||
transientPrimaryError = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
await closeVerifierResources(
|
||||
[
|
||||
...(transientHolder === undefined
|
||||
? []
|
||||
: [() => stopDeleteSharingDeniedReader(transientHolder)]),
|
||||
() => transientRuntime.close(),
|
||||
],
|
||||
transientPrimaryError,
|
||||
);
|
||||
}
|
||||
report.controls = {
|
||||
...report.controls,
|
||||
|
||||
Reference in new issue
Block a user