fix(web-probe): isolate performance capture cdp timeouts
This commit is contained in:
@@ -246,6 +246,7 @@ async function capturePerformanceProfile(command) {
|
||||
const startedAt = new Date(startedAtMs).toISOString();
|
||||
let pageClockStart = null;
|
||||
let stopped = null;
|
||||
let captureError = null;
|
||||
try {
|
||||
pageClockStart = await withHardTimeout(targetPage.evaluate(() => ({ timeOrigin: Math.round(performance.timeOrigin || 0), now: Math.round(performance.now()), url: location.href, path: location.pathname, title: document.title, valuesRedacted: true })), timeoutMs, "performanceCapture page clock exceeded " + timeoutMs + "ms")
|
||||
.catch((error) => ({ error: errorSummary(error), valuesRedacted: true }));
|
||||
@@ -265,6 +266,8 @@ async function capturePerformanceProfile(command) {
|
||||
}));
|
||||
await sleep(durationMs);
|
||||
stopped = await withHardTimeout(session.send("Profiler.stop"), Math.max(timeoutMs, 5000), "Profiler.stop exceeded " + Math.max(timeoutMs, 5000) + "ms");
|
||||
} catch (error) {
|
||||
captureError = error;
|
||||
} finally {
|
||||
if (session) {
|
||||
await withHardTimeout(session.send("Profiler.disable"), 1000, "Profiler.disable exceeded 1000ms").catch(() => {});
|
||||
@@ -274,10 +277,67 @@ async function capturePerformanceProfile(command) {
|
||||
const completedAtMs = Date.now();
|
||||
const afterDrain = await drainPagePerformanceEvents(targetPage, { reason: "performanceCapture-after", groupSeq: sampleSeq, pageRole: targetPageRole, targetPageId, pageEpoch: targetPageEpoch })
|
||||
.catch((error) => ({ ok: false, error: errorSummary(error), count: 0, valuesRedacted: true }));
|
||||
const summaryFile = path.join(captureDir, "summary.json");
|
||||
if (captureError) {
|
||||
const failureKind = isTimeoutErrorMessage(captureError?.message) ? "performance-capture-cdp-timeout" : "performance-capture-failed";
|
||||
const summaryPayload = {
|
||||
ok: false,
|
||||
captureId,
|
||||
type: "performance-cpu-profile",
|
||||
commandId: command.id,
|
||||
label: truncate(command.label || "", 200),
|
||||
startedAt,
|
||||
completedAt: new Date(completedAtMs).toISOString(),
|
||||
durationMs: completedAtMs - startedAtMs,
|
||||
requestedDurationMs: durationMs,
|
||||
pageRole: targetPageRole,
|
||||
pageId: targetPageId,
|
||||
pageEpoch: targetPageEpoch,
|
||||
pageClockStart,
|
||||
currentUrl: pageUrl(targetPage),
|
||||
beforeDrain,
|
||||
afterDrain,
|
||||
failureKind,
|
||||
error: errorSummary(captureError),
|
||||
valuesRedacted: true,
|
||||
};
|
||||
await writeFile(summaryFile, JSON.stringify(summaryPayload, null, 2) + "\n", { mode: 0o600 });
|
||||
const summaryMeta = await fileMeta(summaryFile);
|
||||
artifactSeq += 1;
|
||||
const artifact = {
|
||||
seq: artifactSeq,
|
||||
sampleSeq,
|
||||
ts: new Date().toISOString(),
|
||||
kind: "performance-cpu-profile-failed",
|
||||
captureId,
|
||||
commandId: command.id,
|
||||
summaryPath: summaryFile,
|
||||
summaryByteCount: summaryMeta.byteCount,
|
||||
summarySha256: summaryMeta.sha256,
|
||||
pageRole: targetPageRole,
|
||||
pageId: targetPageId,
|
||||
durationMs: summaryPayload.durationMs,
|
||||
failureKind,
|
||||
valuesRedacted: true,
|
||||
};
|
||||
await appendJsonl(files.artifacts, artifact);
|
||||
await appendJsonl(files.performanceEvents, eventRecord("performance-capture-failed", {
|
||||
captureId,
|
||||
pageRole: targetPageRole,
|
||||
pageId: targetPageId,
|
||||
pageEpoch: targetPageEpoch,
|
||||
artifact,
|
||||
failureKind,
|
||||
error: summaryPayload.error,
|
||||
valuesRedacted: true,
|
||||
}));
|
||||
const wrapped = captureError instanceof Error ? captureError : new Error(String(captureError));
|
||||
wrapped.details = summaryPayload;
|
||||
throw wrapped;
|
||||
}
|
||||
const profile = stopped?.profile || null;
|
||||
const summary = summarizeCpuProfile(profile);
|
||||
const profileFile = path.join(captureDir, "profile.cpuprofile");
|
||||
const summaryFile = path.join(captureDir, "summary.json");
|
||||
const summaryPayload = {
|
||||
ok: true,
|
||||
captureId,
|
||||
|
||||
Reference in New Issue
Block a user