Skip to content

fix: Use async-safe NSException monitor logging - #9324

Merged
philprime merged 5 commits into
mainfrom
test/nsexception-logging-regression
Oct 13, 2026
Merged

philprime merged 5 commits into
mainfrom
test/nsexception-logging-regression

Conversation

@philprime

@philprime philprime commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Use async-safe logging throughout the NSException crash monitor to avoid deadlocking on stdout while other threads are suspended. Log the exception pointer instead of invoking Objective-C description formatting.

Add a regression test that verifies monitor shutdown never invokes the normal SDK log output callback. Initialize logging before capturing shutdown messages and isolate capture from background SDK initialization.

Verification

  • Regression test confirmed failing with the original shutdown log and passing with the fix.
  • Targeted macOS suites: 38 tests, 1 skipped, 0 failures.
  • iOS and macOS builds, formatting, static analysis, and pre-commit checks passed.
  • iOS tests were stopped and skipped as requested.

Related CI failure: https://github.com/getsentry/sentry-cocoa/actions/runs/38266180787/job/114868927446?pr=9251

Closes #9331

@philprime philprime self-assigned this Oct 12, 2026
@philprime philprime added the run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request label Oct 12, 2026
@philprime philprime changed the title test: Reproduce unsafe NSException logging fix: Use async-safe NSException monitor logging Oct 12, 2026
@sentry

sentry Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Size Analysis

1 component analyzed

iOS Builds

Name Configuration Version Download Size Install Size
SDK-Size (iOS)
io.sentry.sample.SDK-Size
Release 9.30.1 (1) 1.3 MB (-298 B) 3.2 MB (0 B)

Configure sentry-cocoa status check rules

@sentry

sentry Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

📲 Install Builds

iOS

🔗 App Name App ID Version Configuration
SDK-Size io.sentry.sample.SDK-Size 9.30.1 (1) Release

⚙️ sentry-cocoa Build Distribution Settings

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1216.94 ms 1250.02 ms 33.08 ms
Size 24.14 KiB 1.38 MiB 1.36 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
d9571ee 1225.67 ms 1259.02 ms 33.35 ms
88e0b6e 1212.93 ms 1251.27 ms 38.33 ms
f0e2408 1224.53 ms 1260.51 ms 35.98 ms
8a8e812 1233.65 ms 1257.19 ms 23.54 ms
c8c3374 1232.96 ms 1263.46 ms 30.50 ms
b0aa013 1208.48 ms 1244.00 ms 35.52 ms
1cba5c4 1230.28 ms 1271.48 ms 41.20 ms
f6e658b 1203.39 ms 1238.34 ms 34.95 ms
89ccfc2 1210.78 ms 1245.02 ms 34.24 ms
545ca7e 1233.89 ms 1269.30 ms 35.41 ms

App size

Revision Plain With Sentry Diff
d9571ee 24.14 KiB 1.39 MiB 1.36 MiB
88e0b6e 24.14 KiB 1.38 MiB 1.36 MiB
f0e2408 24.14 KiB 1.39 MiB 1.36 MiB
8a8e812 24.14 KiB 1.38 MiB 1.36 MiB
c8c3374 24.14 KiB 1.38 MiB 1.36 MiB
b0aa013 24.14 KiB 1.38 MiB 1.36 MiB
1cba5c4 24.14 KiB 1.38 MiB 1.36 MiB
f6e658b 24.14 KiB 1.38 MiB 1.35 MiB
89ccfc2 24.14 KiB 1.38 MiB 1.36 MiB
545ca7e 24.14 KiB 1.39 MiB 1.36 MiB

Previous results on branch: test/nsexception-logging-regression

Startup times

Revision Plain With Sentry Diff
5607a7e 1227.06 ms 1260.29 ms 33.23 ms
7cb0c72 1234.61 ms 1262.02 ms 27.41 ms

App size

Revision Plain With Sentry Diff
5607a7e 24.14 KiB 1.38 MiB 1.36 MiB
7cb0c72 24.14 KiB 1.39 MiB 1.36 MiB

@supervacuus supervacuus 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.

Purely from a fix perspective, this LGTM.

I am not sure how you handle log regressions in this SDK, but replacing SENTRY_LOG_DEBUG with SENTRY_ASYNC_SAFE_LOG_DEBUG (and *WARN respectively) leads to a regression in the sense that the latter is controlled by a compile-time definition that is currently hardcoded to log level ERROR, meaning all logs in this function are compiled out with this PR, so instead of logging async-safe, we are not logging at all.

This can be fine, of course, but I think it's worth raising in a review.

- remark that options no longer control the NSException-monitor logger in the changelog
- allocate and free the buffer for the stack trace outside the thread suspension
- remove the remaining unsafe log calls from sentrycrashcm_nsexception_initStackCursor
- log the trapped exception with name and reason (if available) after we have access to the crash context
@supervacuus

Copy link
Copy Markdown
Collaborator

All raised concerns were resolved in 1141c51

@supervacuus supervacuus self-assigned this Oct 13, 2026

@supervacuus supervacuus 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.

Approving, but @philprime, please have another look. I leave the merge up to you.

@philprime

Copy link
Copy Markdown
Member Author

LGTM too. Thanks for taking this over!

@philprime
philprime enabled auto-merge (squash) October 13, 2026 14:46
@philprime
philprime merged commit 5e4b4ee into main Oct 13, 2026
312 of 320 checks passed
@philprime
philprime deleted the test/nsexception-logging-regression branch October 13, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Use async-safe NSException monitor logging

2 participants