Skip to content

SentryLogcatAdapter StackOverflowError from re-entrant logcat logging #5736

Description

@runningcode

Problem

StackOverflowError in SentryLogcatAdapter (SDK-CRASHES-JAVA-3T3H, 163 occurrences, 4 users, seen up to 8.45.0).

When the Sentry Android Gradle Plugin's logcat instrumentation is enabled, android.util.Log.* calls in the app's own code are rewritten to SentryLogcatAdapter.*. Infinite recursion occurs when code that runs while a Logcat breadcrumb or log is being captured itself calls a rewritten Log.*:

SentryLogcatAdapter.w()addAsBreadcrumb() / addAsLog() → app beforeBreadcrumb / beforeSendLog callback → rewritten Log.w()SentryLogcatAdapter.w() → …

Note: this is not caused by the plugin instrumenting the SDK — io.sentry.* classes are excluded. The re-entry comes from app code reachable during breadcrumb/log processing, so it can only be broken at runtime in the SDK.

Fix

A single thread-local re-entrancy guard (isCapturing) shared across both addAsBreadcrumb() and addAsLog(). Any re-entrant capture on the same thread is a no-op; the real Log.* call is left untouched so logcat output is preserved. Covered by regression tests for both the breadcrumb and logs paths.

Links

Metadata

Metadata

Assignees

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions