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
10 changes: 9 additions & 1 deletion src/main/crash-reporting/process-gone-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type CrashReportDetailValue
} from '../../shared/crash-reporting'
import { getSystemMemoryDetails, memoryKBFieldMB } from './system-memory-details'
import { readZeroRtTimeLimit } from '../linux-rttime-limit'
import {
PRE_GONE_SYSTEM_MEMORY_SAMPLE_INTERVAL_MS,
preGoneSystemMemoryDetails,
Expand Down Expand Up @@ -263,6 +264,12 @@ function sampledProcessIsGone(
)
}

// Why: an inherited zero RLIMIT_RTTIME SIGKILLs children with no dump or OOM (Omarchy without rtkit).
function zeroRtTimeLimitCrashDetails(): Record<string, string> {
const limit = readZeroRtTimeLimit()
return limit ? { rlimitRtTimeSoftUs: limit.soft, rlimitRtTimeHardUs: limit.hard } : {}
}

export function buildProcessGoneCrashDetails(
details: Record<string, unknown>,
crashedProcessType: string
Expand All @@ -274,7 +281,8 @@ export function buildProcessGoneCrashDetails(
const crashDetails: CrashReportDetails = {
...sanitizedDetails,
...liveMetricDetails,
...getSystemMemoryDetails()
...getSystemMemoryDetails(),
...zeroRtTimeLimitCrashDetails()
}
// Compare PID, bucket and creation time to distinguish vanished processes from PID reuse.
const crashedBucket = metricTypeBucket(crashedProcessType)
Expand Down
20 changes: 5 additions & 15 deletions src/main/daemon/daemon-rttime-limit.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import { readFileSync } from 'node:fs'
import { readZeroRtTimeLimit } from '../linux-rttime-limit'

// Why: PTYs inherit the daemon's RLIMIT_RTTIME; at 0 the kernel kills timer-armed jobs (SIGXCPU soft, SIGKILL hard) and unprivileged code can't raise the hard limit (#29745).
// Why: PTYs inherit the daemon's RLIMIT_RTTIME, so a zero limit can kill terminal jobs.
export function warnWhenRealtimeTimeoutIsZero(
log: (event: string, details?: Record<string, unknown>) => void,
platform: NodeJS.Platform = process.platform,
limitsPath = '/proc/self/limits'
): void {
if (platform !== 'linux') {
return
}
let limits: string
try {
limits = readFileSync(limitsPath, 'utf8')
} catch {
return
}
const [, soft, hard] = /^Max realtime timeout\s+(\S+)\s+(\S+)/m.exec(limits) ?? []
if (soft !== '0' && hard !== '0') {
const limit = readZeroRtTimeLimit(platform, limitsPath)
if (!limit) {
return
}
log('rttime-limit-zero', {
soft,
hard,
...limit,
hint:
'Terminals inherit a zero RLIMIT_RTTIME, so the kernel may kill their jobs (exit 137 or 152). ' +
'Installing and enabling RealtimeKit (rtkit), then rebooting, often restores a nonzero limit; ' +
Expand Down
22 changes: 22 additions & 0 deletions src/main/linux-rttime-limit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readFileSync } from 'node:fs'

// Why: at 0 the kernel kills any thread with a CPU timer armed (SIGXCPU at soft, SIGKILL at hard) and unprivileged code can't raise the hard limit (#29745).
export type ZeroRtTimeLimit = { soft: string; hard: string }

/** Raw RLIMIT_RTTIME bounds (us or "unlimited") when either is 0; null otherwise, unreadable, or off Linux. */
export function readZeroRtTimeLimit(
platform: NodeJS.Platform = process.platform,
limitsPath = '/proc/self/limits'
): ZeroRtTimeLimit | null {
if (platform !== 'linux') {
return null
}
let limits: string
try {
limits = readFileSync(limitsPath, 'utf8')
} catch {
return null
}
const [, soft, hard] = /^Max realtime timeout\s+(\S+)\s+(\S+)/m.exec(limits) ?? []
return soft === '0' || hard === '0' ? { soft, hard } : null
}
6 changes: 6 additions & 0 deletions src/main/startup/main-process-ready-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { browserManager } from '../browser/browser-manager'
import { configureBrowserClientPageAutomationRuntime } from '../browser/browser-client-page-automation-runtime'
import { BrowserClientPageCommandError } from '../browser/browser-client-page-command-failure'
import { startPreGoneCrashSampling } from '../crash-reporting/process-gone-diagnostics'
import { readZeroRtTimeLimit } from '../linux-rttime-limit'
import { recordCrashBreadcrumb } from '../crash-reporting/crash-breadcrumb-store'
import { recordProcessGoneCrash } from './main-window-lifecycle-flags'
import { handleGpuChildCrash } from './gpu-lifecycle'
import { isGpuFallbackCrashCandidate } from '../crash-reporting/gpu-crash-fallback-decision'
Expand Down Expand Up @@ -129,6 +131,10 @@ export async function initializeReadyRuntimeServices(): Promise<void> {
}
// Sample live processes: gone-time metrics omit dead children and already-released memory.
startPreGoneCrashSampling()
const rtTimeLimit = readZeroRtTimeLimit()
if (rtTimeLimit) {
recordCrashBreadcrumb('linux_rttime_limit', rtTimeLimit)
}
app.on('child-process-gone', (_event, details) => {
recordProcessGoneCrash('child', details.type, details.reason, details.exitCode ?? null, {
name: details.name,
Expand Down