Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/main/crash-reporting/process-gone-classification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,43 @@ describe('shouldRecordProcessGoneCrash', () => {
})
).toBe(true)
})

it('does not report a renderer kill that shares a whole-process-tree teardown', () => {
// Windows tree kill (F0BMK043Q2V) and Linux SIGKILL (F0BMJ1PC68J) shapes.
expect(
shouldRecordProcessGoneCrash({
source: 'renderer',
processType: 'renderer',
reason: 'killed',
exitCode: 1,
expectedTeardown: 'none',
siblingChildKills: 2
})
).toBe(false)
expect(
shouldRecordProcessGoneCrash({
source: 'renderer',
processType: 'renderer',
reason: 'killed',
exitCode: 9,
expectedTeardown: 'none',
siblingChildKills: 1
})
).toBe(false)
})

it('keeps reporting non-killed renderer exits that coincide with child kills', () => {
expect(
shouldRecordProcessGoneCrash({
source: 'renderer',
processType: 'renderer',
reason: 'crashed',
exitCode: 5,
expectedTeardown: 'none',
siblingChildKills: 2
})
).toBe(true)
})
})

describe('shouldRecoverRendererAfterProcessGone', () => {
Expand Down Expand Up @@ -389,4 +426,16 @@ describe('shouldRecoverRendererAfterProcessGone', () => {
})
).toBe(false)
})

// Bundles F0BMQTGDEGN / F0BNCBF8Q00: child kills land before the renderer kill and
// the recovery reload still restored the window in the same main process. Report
// suppression must not take the reload with it.
it('still recovers a renderer kill that shares a whole-process-tree teardown', () => {
expect(
shouldRecoverRendererAfterProcessGone({
reason: 'killed',
expectedTeardown: 'none'
})
).toBe(true)
})
})
17 changes: 16 additions & 1 deletion src/main/crash-reporting/process-gone-classification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ export function shouldRecordProcessGoneCrash({
serviceName,
reason,
exitCode,
expectedTeardown
expectedTeardown,
siblingChildKills = 0
}: {
source: ProcessGoneSource
processType?: string
serviceName?: string
reason: string
exitCode: number | null
expectedTeardown: ExpectedTeardownScope
siblingChildKills?: number
}): boolean {
// Why: GPU, Network Service, and Audio Service exits are recoverable Chromium
// child-process churn; treating them as app crashes creates noisy user prompts.
Expand All @@ -73,6 +75,12 @@ export function shouldRecordProcessGoneCrash({
if (reason !== 'killed') {
return true
}
// Why: when the OS or user kills the whole process tree, the Chromium children
// die the same way milliseconds from the renderer. That is teardown, not a
// renderer crash, and the exit code alone cannot tell the two apart.
if (source === 'renderer' && siblingChildKills > 0) {
return false
}
// Why: Electron reports expected Chromium teardown during reload/update as
// `killed` + SIGTERM or Windows control termination statuses. Treat real
// crash reasons as reportable, but skip these normal termination shapes.
Expand All @@ -85,6 +93,13 @@ export function shouldRecordProcessGoneCrash({
return !(source === 'renderer' && expectedTeardown === 'renderer-reload')
}

// Why: deliberately ignores sibling tree kills. Suppressing a *report* on that
// signature costs one lost report; suppressing the *reload* strands the user in a
// blank window with no prompt (scheduleRendererRecovery bails synchronously, so
// the exhausted-recovery prompt never fires either). Field bundles F0BMQTGDEGN and
// F0BNCBF8Q00 show the renderer reloading and the same main process living on for
// 37s/136s after a child kill, so the reload is the only thing that recovers those.
// If the tree really is dying, the main process is gone before the 250ms timer.
export function shouldRecoverRendererAfterProcessGone({
reason,
expectedTeardown
Expand Down
108 changes: 108 additions & 0 deletions src/main/crash-reporting/process-gone-recorder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from './crash-breadcrumb-store'
import { ProcessGoneDedupe } from './process-gone-dedupe'
import { recordProcessGoneCrash, type ProcessGoneCrashEvent } from './process-gone-recorder'
import { resetProcessTreeKillWindowForTest } from './process-tree-kill-window'
import { _resetTracerForTests, setActiveSink, type TracerSink } from '../observability/tracer'

type CapturingSink = TracerSink & { records: unknown[]; flushMock: ReturnType<typeof vi.fn> }
Expand Down Expand Up @@ -51,6 +52,7 @@ beforeEach(() => {
})

afterEach(() => {
vi.useRealTimers()
vi.restoreAllMocks()
_resetTracerForTests()
clearCrashBreadcrumbsForTest()
Expand Down Expand Up @@ -364,3 +366,109 @@ describe('recordProcessGoneCrash', () => {
await vi.waitFor(() => expect(record).toHaveBeenCalledTimes(2))
})
})

// Field timeline from crash bundle F0BMK043Q2V (win32 10.0.26200, 1.4.164):
// Network Service killed/1 at 22:09:38.662, GPU killed/1 at .737, renderer
// killed/1 at .746 — one `taskkill` of the tree reported as a renderer crash.
describe('recordProcessGoneCrash whole-process-tree kills', () => {
const networkServiceKill = event({
source: 'child',
processType: 'Utility',
reason: 'killed',
exitCode: 1,
details: {
name: 'Network Service',
serviceName: 'network.mojom.NetworkService',
type: 'Utility'
}
})
const gpuKill = event({
source: 'child',
processType: 'GPU',
reason: 'killed',
exitCode: 1,
details: { serviceName: 'GPU', type: 'GPU' }
})
const rendererKill = event({ reason: 'killed', exitCode: 1 })

beforeEach(() => {
resetProcessTreeKillWindowForTest()
})

it('does not report the renderer kill when the children died first', () => {
const record = vi.fn().mockResolvedValue({ id: 'report-1' })
const dedupe = new ProcessGoneDedupe()
const nowSpy = vi.spyOn(Date, 'now')

nowSpy.mockReturnValue(1_785_708_578_662)
recordProcessGoneCrash({ record } as never, networkServiceKill, dedupe)
nowSpy.mockReturnValue(1_785_708_578_737)
recordProcessGoneCrash({ record } as never, gpuKill, dedupe)
nowSpy.mockReturnValue(1_785_708_578_746)
recordProcessGoneCrash({ record } as never, rendererKill, dedupe)

expect(record).not.toHaveBeenCalled()
expect(getCrashBreadcrumbSnapshot()).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: 'process_gone_suppressed',
data: expect.objectContaining({ source: 'renderer', siblingKills: 2 })
})
])
)
})

// Field timeline from crash bundle F0BMVQ3640H: renderer killed/1 first, then
// Network Service +5ms and GPU +41ms — the same tree kill, opposite order.
it('does not report the renderer kill when the children died right after', async () => {
const record = vi.fn().mockResolvedValue({ id: 'report-1' })
const dedupe = new ProcessGoneDedupe()
vi.useFakeTimers()
vi.setSystemTime(1_785_818_589_464)

recordProcessGoneCrash({ record } as never, rendererKill, dedupe)
vi.advanceTimersByTime(5)
recordProcessGoneCrash({ record } as never, networkServiceKill, dedupe)
vi.advanceTimersByTime(36)
recordProcessGoneCrash({ record } as never, gpuKill, dedupe)
await vi.advanceTimersByTimeAsync(250)

expect(record).not.toHaveBeenCalled()
expect(getCrashBreadcrumbSnapshot()).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: 'process_gone_suppressed',
data: expect.objectContaining({ source: 'renderer', siblingKills: 2 })
})
])
)
})

it('still reports a solitary renderer kill once the sibling window settles', async () => {
const record = vi.fn().mockResolvedValue({ id: 'report-1' })
vi.useFakeTimers()

// Linux exit 61696 self-recovers with no child kills; it must stay reportable.
recordProcessGoneCrash(
{ record } as never,
event({ reason: 'killed', exitCode: 61696 }),
new ProcessGoneDedupe()
)
expect(record).not.toHaveBeenCalled()
await vi.advanceTimersByTimeAsync(250)

expect(record).toHaveBeenCalledOnce()
})

it('ignores child kills that died with a different exit code', async () => {
const record = vi.fn().mockResolvedValue({ id: 'report-1' })
const dedupe = new ProcessGoneDedupe()
vi.useFakeTimers()

recordProcessGoneCrash({ record } as never, gpuKill, dedupe)
recordProcessGoneCrash({ record } as never, event({ reason: 'killed', exitCode: 9 }), dedupe)
await vi.advanceTimersByTimeAsync(250)

expect(record).toHaveBeenCalledOnce()
})
})
68 changes: 57 additions & 11 deletions src/main/crash-reporting/process-gone-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
processGoneDedupe,
type ProcessGoneDedupe
} from './process-gone-dedupe'
import {
countSiblingProcessTreeKills,
observeProcessGoneKill,
PROCESS_TREE_KILL_SETTLE_MS
} from './process-tree-kill-window'
import { getMainProcessLifecycleIdentity } from './main-process-lifecycle-identity'
import { flushActiveSink, startSpan } from '../observability/tracer'

Expand Down Expand Up @@ -75,6 +80,23 @@ function persistFailureData(event: ProcessGoneCrashEvent, error: unknown) {
}
}

function recordSuppressedProcessGone(event: ProcessGoneCrashEvent, siblingKills: number): void {
// Why: Chromium can crash-loop a recoverable child (network service seen at
// 1459/min) and each suppressed event costs a span plus a forced disk flush,
// which both floods the 30-entry ring and evicts the real pre-crash trail.
const suppressedData = processGoneBreadcrumbData(event)
recordCoalescedDurableCrashBreadcrumb({
name: 'process_gone_suppressed',
data: siblingKills > 0 ? { ...suppressedData, siblingKills } : suppressedData,
coalesceKey: suppressedProcessGoneCoalesceKey(suppressedData),
minIntervalMs: SUPPRESSED_PROCESS_GONE_COALESCE_MS
})
}

function siblingProcessTreeKillCount(event: ProcessGoneCrashEvent): number {
return countSiblingProcessTreeKills({ reason: event.reason, exitCode: event.exitCode })
}

export function recordProcessGoneCrash(
store: CrashReportRecorderStore | null,
event: ProcessGoneCrashEvent,
Expand All @@ -83,6 +105,15 @@ export function recordProcessGoneCrash(
if (!isCrashReportReason(event.reason)) {
return
}
if (event.reason === 'killed') {
observeProcessGoneKill({
at: Date.now(),
source: event.source,
reason: event.reason,
exitCode: event.exitCode
})
}
const siblingKills = siblingProcessTreeKillCount(event)
if (
!shouldRecordProcessGoneCrash({
source: event.source,
Expand All @@ -91,21 +122,36 @@ export function recordProcessGoneCrash(
typeof event.details.serviceName === 'string' ? event.details.serviceName : undefined,
reason: event.reason,
exitCode: event.exitCode,
expectedTeardown: event.expectedTeardown
expectedTeardown: event.expectedTeardown,
siblingChildKills: siblingKills
})
) {
// Why: Chromium can crash-loop a recoverable child (network service seen at
// 1459/min) and each suppressed event costs a span plus a forced disk flush,
// which both floods the 30-entry ring and evicts the real pre-crash trail.
const suppressedData = processGoneBreadcrumbData(event)
recordCoalescedDurableCrashBreadcrumb({
name: 'process_gone_suppressed',
data: suppressedData,
coalesceKey: suppressedProcessGoneCoalesceKey(suppressedData),
minIntervalMs: SUPPRESSED_PROCESS_GONE_COALESCE_MS
})
recordSuppressedProcessGone(event, siblingKills)
return
}
if (event.source === 'renderer' && event.reason === 'killed') {
// Why: a tree kill can reach the renderer ~100ms before its children, so let
// the sibling window settle rather than persisting a report the next child
// event would have retracted.
const settleTimer = setTimeout(() => {
const settledSiblingKills = siblingProcessTreeKillCount(event)
if (settledSiblingKills > 0) {
recordSuppressedProcessGone(event, settledSiblingKills)
return
}
persistProcessGoneCrash(store, event, dedupe)
}, PROCESS_TREE_KILL_SETTLE_MS)
settleTimer.unref?.()
return
}
persistProcessGoneCrash(store, event, dedupe)
}

function persistProcessGoneCrash(
store: CrashReportRecorderStore | null,
event: ProcessGoneCrashEvent,
dedupe: ProcessGoneDedupe
): void {
if (!store) {
recordDurableCrashBreadcrumb(
'crash_report_store_unavailable',
Expand Down
56 changes: 56 additions & 0 deletions src/main/crash-reporting/process-tree-kill-window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { ProcessGoneSource } from './process-gone-classification'

// Why: an OS/user kill of the whole Electron tree (taskkill /T, session logout,
// a supervisor SIGKILL) reaches the Chromium children and the renderer as
// independent process-gone events; correlating them is the only way to tell that
// teardown apart from a renderer that died on its own.
export const PROCESS_TREE_KILL_WINDOW_MS = 2_000

// Field offsets between the first and last event of one tree kill run -0.08s to
// +0.10s, so the renderer can arrive before its children; wait this long before
// deciding a renderer kill was solitary.
export const PROCESS_TREE_KILL_SETTLE_MS = 250

// Why: one tree kill produces a handful of events; a deeper ring would only let a
// pre-existing child crash loop outlive the correlation window.
const MAX_TRACKED_KILLS = 16

type TrackedKill = {
at: number
source: ProcessGoneSource
exitCode: number | null
reason: string
}

let trackedKills: TrackedKill[] = []

export function observeProcessGoneKill(kill: TrackedKill): void {
trackedKills.push(kill)
if (trackedKills.length > MAX_TRACKED_KILLS) {
trackedKills = trackedKills.slice(-MAX_TRACKED_KILLS)
}
Comment on lines +27 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep only child kills in the bounded ring.

recordProcessGoneCrash sends every killed source here, but countSiblingProcessTreeKills reads only child entries. Renderer entries can evict matching child kills from the 16-entry ring. A later renderer event can then be reported instead of suppressed.

Ignore non-child observations. Add a regression test with matching child kills followed by 16 renderer kills.

Proposed fix
 export function observeProcessGoneKill(kill: TrackedKill): void {
+  if (kill.source !== 'child') {
+    return
+  }
   trackedKills.push(kill)
   if (trackedKills.length > MAX_TRACKED_KILLS) {
     trackedKills = trackedKills.slice(-MAX_TRACKED_KILLS)
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function observeProcessGoneKill(kill: TrackedKill): void {
trackedKills.push(kill)
if (trackedKills.length > MAX_TRACKED_KILLS) {
trackedKills = trackedKills.slice(-MAX_TRACKED_KILLS)
}
export function observeProcessGoneKill(kill: TrackedKill): void {
if (kill.source !== 'child') {
return
}
trackedKills.push(kill)
if (trackedKills.length > MAX_TRACKED_KILLS) {
trackedKills = trackedKills.slice(-MAX_TRACKED_KILLS)
}

}

/** How many Chromium child processes died the same way inside the window — the
* signature of the whole tree going down rather than one process failing. */
export function countSiblingProcessTreeKills({
reason,
exitCode,
at = Date.now()
}: {
reason: string
exitCode: number | null
at?: number
}): number {
return trackedKills.filter(
(kill) =>
kill.source === 'child' &&
kill.reason === reason &&
kill.exitCode === exitCode &&
Math.abs(at - kill.at) <= PROCESS_TREE_KILL_WINDOW_MS
).length
}

export function resetProcessTreeKillWindowForTest(): void {
trackedKills = []
}
Loading