Skip to content

Android NDK Segfault crash related to sentry_value_set_by_key_n #974

Closed

Description

@aaronjosephsonos

Description

Our Android project has seen crashes related to a Segfault in Sentry native code. There are no places in our code that are directly calling nativeAddBreadcrumb, so thinking something under the hood in Sentry library is making the call. Still, there seems to be a Segfault bug in sentry native code sentry_value.c's file. Thanks in advance for taking a look, and please let me know if there is additional information I can help provide.

When does the problem happen

  • During build
  • During run-time
  • When capturing a hard crash

Environment

  • OS: Have seen crashes on Android 10,12,13,14
  • Compiler:
  • CMake version and config:
  • Sentry version - 7.4.0
  • Sentry compose version - 7.4.0
  • Sentry gradle plugin version - 4.3.0

Subset of Sentry options enabled

            options.enableAllAutoBreadcrumbs(true)
            options.isAnrEnabled = true
            options.isEnableNdk = true
            options.isAttachStacktrace = true
            options.isSendDefaultPii = false
            options.isEnableScopeSync = true
            options.maxBreadcrumbs = 500
            options.isEnableAutoSessionTracking = true
            options.isAttachThreads = true
            options.anrTimeoutIntervalMillis = 10000
            options.isAttachScreenshot = false
            options.tracesSampleRate = null
            options.profilesSampleRate = null
            when (configProvider.buildEnvironment) {
                Environment.Development -> {
                    options.maxBreadcrumbs = 700
                    options.isSendDefaultPii = true
                    options.isAttachScreenshot = true
                    options.tracesSampleRate = 1.0
                    options.profilesSampleRate = 1.0
                }
                Environment.Alpha, Environment.Beta -> {
                    options.tracesSampleRate = 0.4
                    options.profilesSampleRate = 0.4
                }
                Environment.Production -> {
                    // use Sonos (and Sentry) default values
                }
            }

Steps To Reproduce
I myself have not run into this issue and have not found a reliable way to reproduce. Our project has seen the crash approximately 43 times in the past 30 days across 32 users.
Log output

Exception Type: Unknown (SIGSEGV)

Application Specific Information:
Segfault

Thread 0 Crashed:
0   base.apk                        0x71ef138ce0        sentry_value_set_by_key_n (sentry_value.c:482)
1   base.apk                        0x71ef13ae30        [inlined] sentry_value_set_by_key (sentry_value.c:494)
2   base.apk                        0x71ef13ae30        [inlined] timestamp_value (sentry_value.c:1163)
3   base.apk                        0x71ef13ae30        sentry_value_new_breadcrumb_n (sentry_value.c:1173)
4   base.apk                        0x71ef0b01f4        Java_io_sentry_android_ndk_NativeScope_nativeAddBreadcrumb (sentry.c:174)
5   base.odex                       0x7160a890a0        <unknown> + 486952964256

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Apr 1, 2024
  2. supervacuus commented on Apr 2, 2024

    @supervacuus
    Collaborator

    Hi @aaronjosephsonos, thanks for the report.

    There are no places in our code that are directly calling nativeAddBreadcrumb, so thinking something under the hood in Sentry library is making the call.

    Whenever you add breadcrumbs to your Android application, a call will be made to nativeAddBreadcrumb() because breadcrumbs will be synced to the Native SDK.

    You might do this directly via any Interface providing an addBreadcrumb() method or indirectly via an integration that automatically adds them, for instance, during an activity state or navigation change.

    Still, there seems to be a Segfault bug in sentry native code sentry_value.c's file. Thanks in advance for taking a look, and please let me know if there is additional information I can help provide.

    I understand you currently cannot reproduce this locally, but any additional context (like a logcat output or a tombstone) will be helpful for me. Do you get these reports via Sentry? If so, could you provide a link to one of our employees, karl.struggl@sentry.io, for one such event?

    This is the second report from Android, in which a freshly created object has either uninitialized members or refers to memory it doesn't own. AFAICR, this also appeared while adding a timestamp to a breadcrumb object (i.e., the first key to be added). Back then, I thought we might hit an issue with the page_allocator because it happened in the signal handler, but this seems to be happening outside any raised signal.

    In any case, I will investigate.

    Our project has seen the crash approximately 43 times in the past 30 days across 32 users.

    Does this issue appear only with recent updates?

  3. added
    Bugsomething isn't working as it should
    on Apr 2, 2024
  4. supervacuus commented on Apr 2, 2024

    @supervacuus
    Collaborator

    Cc @kahest: While my hopes are low that we will be able to repro this quickly, this is another concrete driver for #962

  5. aaronjosephsonos commented on Apr 2, 2024

    @aaronjosephsonos
    Author

    Thanks for the response @supervacuus!

    Whenever you add breadcrumbs to your Android application, a call will be made to nativeAddBreadcrumb() because breadcrumbs will be synced to the Native SDK.

    You might do this directly via any Interface providing an addBreadcrumb() method or indirectly via an integration that automatically adds them, for instance, during an activity state or navigation change.

    Ahh thats good to know. We are calling addBreadcumbs pretty often in our code, basically anytime we log something we are calling addBreadcrumbs. So potentially some log message that occasionally occurs may be causing this bug to pop up.

    I understand you currently cannot reproduce this locally, but any additional context (like a logcat output or a tombstone) will be helpful for me. Do you get these reports via Sentry? If so, could you provide a link to one of our employees, karl.struggl@sentry.io, for one such event?

    Yes, we get these reports in Sentry. My workplace has a Slack channel with Sentry reps. I will share the events in that channel with them, and hopefully they will be able to forward them to you. I'll keep you posted with that correspondance.

    Does this issue appear only with recent updates?

    The first crash was reported on February 16, at that time we were on Sentry Android version 6.29.0 and Sentry android gradle version 3.12.0

  6. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Apr 2, 2024
  7. supervacuus commented on Apr 2, 2024

    @supervacuus
    Collaborator

    So potentially some log message that occasionally occurs may be causing this bug to pop up.

    I hope it is not a particular log message (although that would make the case easy). The breadcrumbs are a pretty beaten path, especially on mobile, and if the error were in that code, I would be surprised that we're not getting many more reports. But it is hard to say at this point.

    I will share the events in that channel with them, and hopefully they will be able to forward them to you. I'll keep you posted with that correspondence.

    Thanks!

  8. 26 remaining items

  9. kahest commented on Mar 24, 2025

    @kahest
    Contributor

    @deathlyrage thanks for reaching out. We see only very few events for this crash so it's currently unclear if the version changes affect this. We're investigating and will follow up here

  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Mar 24, 2025
  11. jpnurmi commented on Sep 1, 2026

    @jpnurmi
    Collaborator

    It's been 1.5 years since the last report. #1446 addressed a relevant allocator race, while #2035 and #2036 added regression and ASan coverage.

    We'll close this for now, but please don't hesitate to let us know if the problem persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AndroidBugsomething isn't working as it shouldErrorsissues relates to the error reporting productNativeplatform label

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions