Skip to content

Comments

fix: split inproc handler thread#1446

Merged
supervacuus merged 142 commits intomasterfrom
fix/split_inproc_handler_thread
Feb 18, 2026
Merged

fix: split inproc handler thread#1446
supervacuus merged 142 commits intomasterfrom
fix/split_inproc_handler_thread

Conversation

@supervacuus
Copy link
Collaborator

@supervacuus supervacuus commented Nov 10, 2025

This is a more elaborate, long-term fix to getsentry/sentry-java#4830 than #1444.

It also finishes the work done here: #1088
And fixes the issues raised here:

So, while the driver for this PR is a downstream issue that exposes the signal-unsafety of some parts of the current inproc implementation, it also addresses a much broader range of concerns that regularly affect inproc users on all platforms.

At a high level, it introduces a separate handler thread for inproc, which the signal handler (or UEF on Windows) wakes after it exchanges crash context data.

The idea is that we minimize signal handler/UEF to do the least amount of syscall stuff (or at least the subset documented in the signal-safety man-page), while the handler thread can execute functions outside that range (with limitations, since thread sync and heap allocations are still problematic). This allows us to reuse stdio functionality like formatters without running squarely into UB territory or having to rewrite all utilities to async-signal-safe versions, as in #1444.

There are a few considerable changes to mention:

  • since we run the event construction in a separate handler thread, the use of backtrace() or any unwinder that runs from the "current" instruction address is entirely useless (ignoring the fact that backtrace() was always signal-unsafe to begin with, which itself was the source of crashes, hangs or just empty stack traces).
  • this means we require a "user context"-based stack walker in inproc, which we already partially acknowledged in Using libunwind for mac, since backtrace do not expect thread context… #1088 and fix: support musl on Linux #1233.
  • on Linux, this PR requires libunwind (the nognu implementation, not the llvm one, which is a pure C++ exception unwinder), which is a breaking change (at least in the sense that users now require an additional dependency at build and runtime). This means that the "general" Linux usage is now the same as with the musl libc environments.
  • on macOS, we provide a user context stack-walker based on frame pointer records for arm64 and x86-64, and use the system-provided libunwind for the default stack-trace from a call-site. It turned out that the system-provided libunwind wasn't safe enough to use in the context of the signal handler (either led to hangs or had issues with escaping the trampoline). This means users can now use inproc on macOS again (if their code is compiled without omitting frame pointers, which is always the case by default on macOS).

Further improvements/fixes (summarizing the 30 commits, which I didn't want to squash):

  • the libunwind-based unwinder modules now also validate retrieved ucontext pointers against memory mapping (for Linux and macOS)
  • got rid of all remaining __sync functions and replaced them with __atomic (especially the signal handler blocking logic and the spinlock)
  • rectified the inconsistent usage of C++ new with std::nothrow throughout the affected backend code (including the initialization of crashpad_state_t, which still used malloc and memset although it has std::atomic members)
  • cleaned up the CMake configure phase of the integration test suite.
  • ensures that test fixtures do not end up in macOS bundles
  • fixes build issues with by-default PIE and LTO builds
  • musl is no longer a special case "Linux" in the build script
  • fixes a couple of warnings and test-case instabilities
  • introduce macos-26 build config

TODOs:

  • finish the x86-64 stackwalker for macOS (and clean up the code)
  • Figure out if we need the libbacktrace fallback at all and how to handle it.
  • provide a module-level description of the new mechanism in inproc
  • Decide on having the change
  • Update documentation

* use `std::nothrow` `new` consistently to keep exception-free semantics for allocation
* rename static crashpad_handler to have no module-public prefix
* use `nullptr` for arguments where we previously used 0 to clarify that those are pointers
* eliminate the `memset()` of the `crashpad_state_t` initialization since it now contains non-trivially constructable fields (`std::atomic`) and replace it with `new` and an empty value initializer.
…ld, since libraries like libunwind.a might be packaged without PIC.
…ms with architecture prefixes (32-bit Linux)
…stack

also ensure to get the first frame
harmonize libunwind usage
@supervacuus supervacuus requested review from JoshuaMoelans and jpnurmi and removed request for jpnurmi February 13, 2026 08:43
Copy link
Collaborator

@jpnurmi jpnurmi left a comment

Choose a reason for hiding this comment

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

Are the crashpad and breakpad changes related?

@supervacuus
Copy link
Collaborator Author

Are the crashpad and breakpad changes related?

Only in the sense that I was getting compiler errors with Werror on one of my test setups, and I thought: Why not fix it. The changes are not behavioral at all: the initial code was already written as if new could return a nullptr.

* remove return value from sentry__addr_to_string()

* vendor libunwind with a minimal Linux cmake setup for Linux x86, x86_64 and aarch64

* set CMAKE_SYSTEM_PROCESSOR=i686 for SENTRY_BUILD_FORCE32

* build libunwind with C11 target props

* fix the source instead of setting C11 on target

* move unw_context_t out of the else block.

* enable ASM for libunwind

* remove the ASM in ENABLED_LANGUAGES check for the breakpad build

* remove unused files

* document all changes

* also get rid of humongous autoreconf generated release artifacts
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.

jpnurmi added a commit to getsentry/sentry-dotnet that referenced this pull request Feb 18, 2026
Removed note about 'libunwind' requirement for Linux.
Update CHANGELOG with breaking changes and new features.
@supervacuus
Copy link
Collaborator Author

@jpnurmi, I saw you also ran against this branch. Any reasons not to merge this?

Copy link
Collaborator

@jpnurmi jpnurmi left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Tested with sentry-dotnet: getsentry/sentry-dotnet#4926

#endif

/**
* Inproc Backend Introduction
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I really tried not to be terse here because there is a lot of non-obvious, non-explicit stuff going on. At the same time, it required many explicit code changes to model the domain, which could feel overwhelming without the matching prose.

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.

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.

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.

@supervacuus supervacuus merged commit eecc7fa into master Feb 18, 2026
46 checks passed
@supervacuus supervacuus deleted the fix/split_inproc_handler_thread branch February 18, 2026 12:22
@getsentry getsentry deleted a comment from github-actions bot Feb 19, 2026
supervacuus added a commit to getsentry/sentry-docs that referenced this pull request Feb 20, 2026
## DESCRIBE YOUR PR
This PR updates the native docs wrt the changes introduced here:
getsentry/sentry-native#1446

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [x] Checked Vercel preview for correctness, including links
- [x] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

## LEGAL BOILERPLATE

<!-- Sentry employees and contractors can delete or ignore this section.
-->

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.

## EXTRA RESOURCES

- [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
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.

4 participants