Skip to content

feat: Sentry native crash backend#1433

Open
mujacica wants to merge 112 commits intomasterfrom
feat/sentry_native_backend
Open

feat: Sentry native crash backend#1433
mujacica wants to merge 112 commits intomasterfrom
feat/sentry_native_backend

Conversation

@mujacica
Copy link
Contributor

  • Sentry native crash backend
  • Out-of-process daemon/handler
  • MacOS/Android/Windows/Linux support
  • Integration with external crash reporter
  • IPC/SHM/Signaling multi-platform implementation
  • Minidump writers for all platforms
  • In-process option (process_crash function)
  • Different options for Minidump sizes
  • Full sentry-codebase integration
  • Sentry logger integration
  • Sentry debug-flags integration

@mujacica
Copy link
Contributor Author

@sentry review

1 similar comment
@mujacica
Copy link
Contributor Author

@sentry review

@mujacica mujacica force-pushed the feat/sentry_native_backend branch from 216b3cd to e4cd98c Compare January 15, 2026 10:28
@mujacica
Copy link
Contributor Author

@sentry review

@mujacica
Copy link
Contributor Author

@cursor review

@mujacica
Copy link
Contributor Author

@cursor review

@mujacica mujacica force-pushed the feat/sentry_native_backend branch from d634773 to eb77775 Compare January 15, 2026 19:37
@mujacica
Copy link
Contributor Author

@sentry review

@mujacica mujacica force-pushed the feat/sentry_native_backend branch from d46d50a to d38b5e1 Compare January 17, 2026 08:10
@mujacica mujacica marked this pull request as ready for review January 17, 2026 11:50
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@mujacica mujacica force-pushed the feat/sentry_native_backend branch from d33258f to 71ea60d Compare January 20, 2026 10:01
@mujacica mujacica changed the title (POC) feat: Sentry native crash backend feat: Sentry native crash backend Jan 20, 2026
@github-actions
Copy link

github-actions bot commented Jan 20, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 34022b6

@linear
Copy link

linear bot commented Feb 5, 2026

@mujacica mujacica force-pushed the feat/sentry_native_backend branch from 79d2b05 to a6af7d6 Compare February 5, 2026 09:54
- Extract duplicated helper functions from Linux/macOS minidump writers
  into new common files (sentry_minidump_common.c/h)
- Fix Windows OpenProcess to use minimal required permissions
  (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ) instead of PROCESS_ALL_ACCESS
- Add validation to skip setting debug_id for modules without valid PDB info
  (all-zero UUID) to fix Windows symbolication issues

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add length validation in sentry__minidump_write_string to prevent
  integer overflow when calculating UTF-16 buffer size
- Remove unused struct linux_fxsave from Linux minidump writer
- Remove unused SENTRY_CRASH_PID_STRING_SIZE constant

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
mujacica and others added 3 commits February 5, 2026 13:13
The crashed thread's stacktrace was appearing both in
exception.values[0].stacktrace AND threads.values[0].stacktrace.
This duplication could confuse Sentry's symbolicator.

Fix: Only add stacktrace to non-crashed threads in the threads array,
since the crashed thread's stacktrace is already in the exception.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add defensive uppercase conversion for Windows PE code_id formatting.
While %lX should produce uppercase, some runtime environments may differ.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Cast e_shentsize to size_t before multiplication to prevent integer
overflow. Both operands are uint16_t which promotes to int, and the
maximum product (65535 * 65535) exceeds INT32_MAX.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace strlen() and snprintf() with signal-safe alternatives:
- Add safe_strlen() function for all Unix platforms (moved from macOS-only)
- Add safe_uint_to_str() for signal-safe integer to string conversion
- Add safe_build_stack_path() for signal-safe path building
- Replace strlen() with sizeof()-1 for string literals in signal handler
- Replace snprintf() with manual string building using signal-safe helpers

These functions avoid calling async-signal-unsafe libc functions from
within the crash signal handler, preventing potential deadlocks or
corruption during crash handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
mujacica and others added 4 commits February 5, 2026 14:20
Windows exception codes like 0xC0000005 (Access Violation) are unsigned
32-bit values. When cast to int32, values >= 0x80000000 become negative,
which causes symbolicator to fail with "invalid value: integer -1073741819,
expected u32".

Use sentry_value_new_uint64() for Windows exception codes to preserve
the unsigned value.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The previous implementation performed byte-by-byte conversion which only
worked for ASCII. Multi-byte UTF-8 sequences (e.g., "é" = 0xC3 0xA9) were
incorrectly converted to separate UTF-16 code units (0x00C3 0x00A9 instead
of 0x00E9), producing garbled text in module names.

Implement proper UTF-8 decoding that:
- Handles 1-4 byte UTF-8 sequences correctly
- Produces UTF-16 surrogate pairs for code points > U+FFFF
- Uses replacement character (U+FFFD) for invalid sequences
- Rejects overlong encodings and invalid surrogates

This fixes symbolication for users with international characters in paths.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add defensive deduplication check when enumerating threads from the
crashed process on Windows. This prevents duplicate thread entries
in the event JSON if CreateToolhelp32Snapshot returns duplicates
or if there's a race condition during thread enumeration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously, enumerate_threads_from_process only stored thread IDs
but set CONTEXT to zeros for non-crashed threads. This meant we
couldn't walk their stacks, resulting in threads with no labels
in the Sentry UI (labels come from symbolicated top stack frames).

Now we:
- Open each thread with THREAD_GET_CONTEXT access
- Suspend the thread briefly
- Capture the full CPU context via GetThreadContext
- Resume the thread

This allows the daemon to walk all thread stacks using StackWalk64,
providing proper stack traces that can be symbolicated to show
meaningful thread labels.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
mujacica and others added 2 commits February 5, 2026 15:08
- Add secondary deduplication when building thread list for event JSON
- Verify crashed thread at index 0 matches crashed_tid before enumeration
- Fix mismatch if threads[0].thread_id differs from crashed_tid
- Add debug logging to track thread enumeration
- Log warnings when duplicate thread IDs are detected and skipped

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The shared memory was being zeroed twice in the Linux IPC initialization
when !shm_exists: once at line 124 and again at line 162. The first memset
was completely redundant since the second one immediately overwrites the
same memory region before initializing magic, version, and state fields.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mujacica mujacica force-pushed the feat/sentry_native_backend branch from e9c32f5 to d75958d Compare February 5, 2026 14:25
Copy link

@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 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

mujacica and others added 5 commits February 5, 2026 15:39
- Remove defensive thread deduplication at event-building level
- Remove thread ID mismatch check/fix
- Add diagnostic logging at key points:
  - enumerate_threads start (shows crashed_tid and threads[0].id)
  - write_envelope_with_native_stacktrace (shows minidump_path and include_threads)
  - Windows thread addition (shows thread count being added)

The duplicate thread issue needs proper root cause analysis.
These logs will help identify whether:
- Threads are duplicated in ctx->platform.threads[]
- The threads are being added to the event twice
- include_threads logic has issues

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Check lseek return value when saving position in module list stream
- Check lseek return value when restoring position after module update
- Fix SENTRY_DEBUGF formatting to comply with clang-format

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add detailed logging to identify where thread duplication occurs:
- Log whether event JSON contains threads (and count)
- Log mode, use_native_mode, need_minidump at decision point
- Log minidump_path being passed to write_envelope_with_native_stacktrace
- Warn if threads are in event when include_threads should be false

This will help determine if duplication is in our code or server-side.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add verify_no_thread_duplication() to detect when threads appear twice
- Add print_daemon_logs() to output daemon log files for debugging
- Call thread verification in all E2E crash mode tests
- Print daemon logs after each crash for Windows thread investigation

The daemon already logs to {database_path}/sentry-daemon-{id}.log when
debug mode is enabled. This change makes those logs visible in CI output.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
mujacica and others added 4 commits February 5, 2026 16:46
Debug output to understand what API returns:
- Print all thread IDs and properties
- Detect if multiple thread entries exist in API response
- Help diagnose thread duplication issue on Windows

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant