Skip to content

fix(native): prevent shared memory leak on crash#1664

Merged
jpnurmi merged 2 commits intomasterfrom
jpnurmi/fix/native-unlink-shm
Apr 23, 2026
Merged

fix(native): prevent shared memory leak on crash#1664
jpnurmi merged 2 commits intomasterfrom
jpnurmi/fix/native-unlink-shm

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Apr 23, 2026

The native backend was leaking a /dev/shm/s-<id> entry per crash. The app's sentry__crash_ipc_free only unlinks during clean shutdown, and the daemon never unlinked. Under Docker's default 64 MB /dev/shm, a few dozen crashes fill the tmpfs and the next memset page-fault SIGBUSes silently. Surfaced in #1545, which adds more native crash tests.

Add sentry__crash_ipc_unlink and call it from the daemon's cleanup path when crash_processed || !is_parent_alive. The app keeps unlinking from its own sentry__crash_ipc_free via the existing !is_daemon guard, so it still owns the unlink during normal teardown.

Each native-backend crash leaks a /dev/shm/s-<id> entry: the app's _free
only runs on clean shutdown, and the daemon previously never unlinked.
Under Docker's default 64 MB /dev/shm a few dozen leaks fill the tmpfs;
the next ftruncate succeeds (lazy) but the first page-fault from memset
takes a SIGBUS and the app dies silently.

Add sentry__crash_ipc_unlink() and call it from the daemon's cleanup
path when crash_processed is set or the parent is no longer alive. Keep
the !is_daemon guard in _free so the app still owns the unlink during
normal shutdown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread src/backends/native/sentry_crash_ipc.c
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4c53d11. Configure here.

Comment thread src/backends/native/sentry_crash_ipc.c Outdated
Comment thread src/backends/native/sentry_crash_ipc.c Outdated
@jpnurmi jpnurmi changed the title WIP: fix(native): prevent /dev/shm leak on crash WIP: fix(native): prevent shared memory leak on crash Apr 23, 2026
@jpnurmi jpnurmi force-pushed the jpnurmi/fix/native-unlink-shm branch from 4c53d11 to affcb93 Compare April 23, 2026 07:24
@jpnurmi jpnurmi changed the title WIP: fix(native): prevent shared memory leak on crash fix(native): prevent shared memory leak on crash Apr 23, 2026
@jpnurmi jpnurmi requested a review from mujacica April 23, 2026 08:00
@jpnurmi jpnurmi merged commit 11b60bd into master Apr 23, 2026
61 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/fix/native-unlink-shm branch April 23, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants