Repository navigation
fix(crash-reporting): a fatal OOM crashes with a report instead of livelocking; name the worker and payload behind it #43327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b108841
fix(main): crash instead of spinning on a fatal OOM, and name the wor…
brennanb2025 5fbf408
test(worker-threads): ledger names the sender and frees its slot on exit
brennanb2025 529441f
fix(worker-threads): refuse fault-signal listeners synchronously, sur…
brennanb2025 568a552
fix(worker-threads): cast-free guard and ledger, keyed collections co…
brennanb2025 192cb25
fix(worker-threads): visit each payload object once under one entry b…
brennanb2025 0442b55
fix(worker-threads): split main heap into old and large-object space …
brennanb2025 47f1e13
fix(native-chat): refuse a journal reader reply over 256 MB instead o…
brennanb2025 27e60c8
fix(native-chat): cap reader replies at 64 MB from measured decode co…
brennanb2025 b000c36
test(crash-reporting): a real process with proper-lockfile holds no S…
brennanb2025 7e5beb7
fix(native-chat): measure any reader reply the bounded walk cut short…
brennanb2025 41be42c
chore(worker-threads): satisfy lint/format, split hang worker-send pa…
brennanb2025 cc3c160
chore(worker-threads): typed calls instead of Reflect in the send led…
brennanb2025 bca8bf2
fix(native-chat): page items-by-kind visits by 8 MiB of JSON so a pag…
brennanb2025 6f0c0c4
perf(native-chat): read items-by-kind payloads lazily so rows past th…
brennanb2025 99efae1
fix(native-chat): never refuse a reader reply that carries one stored…
brennanb2025 2bd72db
fix(worker-threads): list the spawn module's new imports in the web t…
brennanb2025 4b83fd3
Merge remote-tracking branch 'origin/main' into brennanb2025/worker-o…
brennanb2025 431c668
fix(worker-threads): walk Map keys through built-in accessors, bound …
brennanb2025 3ae06af
refactor(native-chat): keep the items-by-kind payload lookup's SQLite…
brennanb2025 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/crash-reporting/fatal-signal-listener-guard.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { spawnSync } from 'node:child_process' | ||
| import { EventEmitter } from 'node:events' | ||
| import { createRequire } from 'node:module' | ||
| import { resolve } from 'node:path' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { installFatalSignalListenerGuard } from './fatal-signal-listener-guard' | ||
|
|
||
| const require = createRequire(import.meta.url) | ||
| const loader = require.resolve('tsx/cjs') | ||
| const guard = resolve('src/main/crash-reporting/fatal-signal-listener-guard.ts') | ||
|
|
||
| /** | ||
| * A real process with the shipped proper-lockfile (signal-exit). A listener is the hang's | ||
| * precondition: when the trap is the thread's own instruction, its JS handler never runs. A raised | ||
| * SIGTRAP lets the loop run, so the exit alone can't tell; the listener count does. | ||
| */ | ||
| function trapWithShippedLockfile(order: 'guard-first' | 'lockfile-first'): { | ||
| signal: NodeJS.Signals | null | ||
| listeners: { trap: number; term: number } | ||
| } { | ||
| const child = spawnSync( | ||
| process.execPath, | ||
| [ | ||
| '-e', | ||
| `require(${JSON.stringify(loader)}) | ||
| const { installFatalSignalListenerGuard } = require(${JSON.stringify(guard)}) | ||
| if (process.argv[1] === 'guard-first') installFatalSignalListenerGuard() | ||
| require('proper-lockfile') | ||
| if (process.argv[1] === 'lockfile-first') installFatalSignalListenerGuard() | ||
| process.stdout.write(JSON.stringify({ | ||
| trap: process.listenerCount('SIGTRAP'), | ||
| term: process.listenerCount('SIGTERM') | ||
| })) | ||
| process.kill(process.pid, 'SIGTRAP') | ||
| setTimeout(() => process.exit(0), 2000)`, | ||
| order | ||
| ], | ||
| { encoding: 'utf8', timeout: 20_000 } | ||
| ) | ||
| return { signal: child.signal, listeners: JSON.parse(child.stdout) } | ||
| } | ||
|
|
||
| describe('installFatalSignalListenerGuard', () => { | ||
| it('never holds a fault-signal listener, before or after install, keeping others', () => { | ||
| const target = new EventEmitter() | ||
| const noop = (): void => {} | ||
| target.on('SIGABRT', noop) | ||
| installFatalSignalListenerGuard(target) | ||
| // What signal-exit registers when proper-lockfile loads, through every registration API. | ||
| target.on('SIGTRAP', noop) | ||
| target.addListener('SIGABRT', noop) | ||
| target.once('SIGIOT', noop) | ||
| target.prependListener('SIGSYS', noop) | ||
| target.prependOnceListener('SIGSEGV', noop) | ||
| target.on('SIGTERM', noop) | ||
| target.once('SIGINT', noop) | ||
|
|
||
| for (const signal of ['SIGTRAP', 'SIGABRT', 'SIGIOT', 'SIGSYS', 'SIGSEGV']) { | ||
| expect(target.listenerCount(signal)).toBe(0) | ||
| } | ||
| expect(target.listenerCount('SIGTERM')).toBe(1) | ||
| expect(target.listenerCount('SIGINT')).toBe(1) | ||
| }) | ||
|
|
||
| // Windows has no SIGTRAP to raise; the listener guard itself is covered above. | ||
| it.skipIf(process.platform === 'win32').each(['guard-first', 'lockfile-first'] as const)( | ||
| 'proper-lockfile leaves no SIGTRAP listener, keeps its SIGTERM cleanup, and SIGTRAP kills (%s)', | ||
| (order) => { | ||
| const { signal, listeners } = trapWithShippedLockfile(order) | ||
| expect(listeners).toEqual({ trap: 0, term: 1 }) | ||
| expect(signal).toBe('SIGTRAP') | ||
| } | ||
| ) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { EventEmitter } from 'node:events' | ||
|
|
||
| /** | ||
| * Signals raised by the faulting instruction itself. A JS listener on one (signal-exit, loaded by | ||
| * proper-lockfile, adds SIGTRAP and SIGABRT) makes libuv's handler return to that instruction, so | ||
| * Chromium's fatal OOM trap re-fires forever at full CPU instead of crashing with a report. | ||
| * The listener itself never runs: the faulting thread never returns to the event loop. | ||
| */ | ||
| const SYNCHRONOUS_FAULT_SIGNALS = [ | ||
| 'SIGTRAP', | ||
| 'SIGABRT', | ||
| 'SIGIOT', | ||
| 'SIGSYS', | ||
| 'SIGILL', | ||
| 'SIGBUS', | ||
| 'SIGFPE', | ||
| 'SIGSEGV' | ||
| ] as const | ||
| const FAULT_SIGNALS: ReadonlySet<unknown> = new Set(SYNCHRONOUS_FAULT_SIGNALS) | ||
|
|
||
| const LISTENER_METHODS = [ | ||
| 'on', | ||
| 'addListener', | ||
| 'once', | ||
| 'prependListener', | ||
| 'prependOnceListener' | ||
| ] as const | ||
|
|
||
| /** | ||
| * Drops these listeners and refuses new ones before Node starts libuv's handler for them. Bundled | ||
| * externals (proper-lockfile) load before entry code, so their listeners exist at install; dropping | ||
| * them restores the default action, which the crash reporter started later still catches. | ||
| */ | ||
| export function installFatalSignalListenerGuard(target: EventEmitter = process): void { | ||
| for (const signal of SYNCHRONOUS_FAULT_SIGNALS) { | ||
| target.removeAllListeners(signal) | ||
| } | ||
| for (const method of LISTENER_METHODS) { | ||
| const original = target[method] | ||
| Object.defineProperty(target, method, { | ||
| configurable: true, | ||
| writable: true, | ||
| value: function ( | ||
| this: EventEmitter, | ||
| event: string | symbol, | ||
| listener: (...args: unknown[]) => void | ||
| ): EventEmitter { | ||
| return FAULT_SIGNALS.has(event) ? this : original.call(this, event, listener) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.