Skip to content

feat: in proc App Hang capture#1806

Merged
bitsandfoxes merged 26 commits into
masterfrom
feat/app-hang-inproc
Jun 22, 2026
Merged

feat: in proc App Hang capture#1806
bitsandfoxes merged 26 commits into
masterfrom
feat/app-hang-inproc

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Resolves https://github.com/getsentry/team-gdx/issues/155
Alternative or parallelization of #1780

The Goal

The goal is to have a mechanism that allows capture of frozen/stuck main threads. The resulting event should provide the same level of detail and insights as actual errors. This means contexts, tags, breadcrumbs, trace, and stack trace.

The How

With an in-proc thread stackwalker, we pause (lol) the hung thread, get to the stack, and create a proper event.
Whatever is considered the main thread periodically calls heartbeat on the SDK. This reset a timestamp. The monitor captures the state of the stuck process should the timestamp exceed the configured threshold.

For this the PR adds the following new API:

  • sentry_options_set_app_hang_enabled:
  • sentry_options_set_app_hang_timeout_ms
  • sentry_app_hang_heartbeat

Limitations & Followups:

  • Limited to x64 on Windows. Needs a follow up for ARM64.
  • Letting a variable number of threads emit a heartbeat and monitor those

The Result

macOS

Screenshot 2026-06-16 at 17 51 59

Windows

Screenshot 2026-06-16 at 17 55 52

@github-actions

github-actions Bot commented Jun 16, 2026

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

Generated by 🚫 dangerJS against c07e41c

@bitsandfoxes bitsandfoxes marked this pull request as ready for review June 17, 2026 14:48
Comment thread src/sentry_app_hang_latch.c
Comment thread src/sentry_core.c
Comment thread include/sentry.h
Comment thread src/sentry_app_hang_monitor.c
Comment thread src/sentry_app_hang_latch.c
Comment thread src/sentry_app_hang_monitor.c Outdated
Comment thread src/sentry_thread_stackwalk_posix.c
Comment thread src/sentry_app_hang_monitor.c
Comment thread src/sentry_thread_stackwalk_posix.c
Comment thread src/sentry_app_hang_monitor.c
@bitsandfoxes bitsandfoxes requested a review from a team June 17, 2026 15:40
Comment thread src/sentry_core.c
Comment thread src/sentry_thread_stackwalk_posix.c
Comment thread src/sentry_app_hang_monitor.c
Comment thread include/sentry.h Outdated

@limbonaut limbonaut left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great stuff! This was a good read - learned a lot of new things about sentry-native. Surprisingly concise PR for what it does. Got my brain cooked trying to understand the nuances between the various unwinder implementations 😅 You may want to have others take a look too, esp someone who knows unwinders well.

Let's try integrating this into Godot. In the context of the Godot SDK, Godot Engine doesn't provide an API for inspecting script stack traces from other threads, so this would only be of use for issues triggered in the native code (engine or C++ extension). Now I'm wondering what would be required to make script traces possible for App Hangs. And same for CoreCLR .NET.

Comment thread src/sentry_app_hang_latch.h Outdated
Comment thread include/sentry.h
Comment thread src/sentry_sync.h

@tustanivsky tustanivsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM - tested this in Unreal on Windows, Linux and macOS (getsentry/sentry-unreal#1427) and it works as expected. I also confirmed that in-process hang tracking allows us to bypass the IPC limitations in sandboxed Mac applications.

Comment thread src/sentry_thread_stackwalk_posix.c

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

There are 3 total unresolved issues (including 1 from previous review).

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 88e1e73. Configure here.

Comment thread src/sentry_thread_stackwalk_posix.c
Comment thread src/sentry_thread_stackwalk_posix.c
Comment thread src/sentry_app_hang_monitor.c

@JoshuaMoelans JoshuaMoelans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work 🚀 LGTM

@bitsandfoxes bitsandfoxes merged commit 1cee097 into master Jun 22, 2026
63 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/app-hang-inproc branch June 22, 2026 15:08
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