fix(android): clear static event mapper on engine detach - #1112
Draft
c-tshibas wants to merge 2 commits into
Draft
fix(android): clear static event mapper on engine detach#1112c-tshibas wants to merge 2 commits into
c-tshibas wants to merge 2 commits into
Conversation
The RUM/Logs event mapper is stored in a static, process-wide singleton that is only ever overwritten, never cleared. When a Flutter engine is detached (app backgrounded and killed, hot restart, or Activity recreation on a config change), the mapper field still holds a JNI reference tied to that now-destroyed engine's Dart isolate. dd-sdk-android's RUM/Logs core keeps writing/uploading queued events on a background thread independent of any Flutter engine's lifecycle. When it invokes the stale mapper to serialize an event, it crashes with a SIGSEGV inside CallObjectMethod at a deterministic offset -- the fingerprint of a JNI call into a freed/torn-down reference. Clears the mapper in detachFromEngine() for both DatadogRumPlugin and DatadogLogsPlugin, and marks both mapper fields @volatile so a clear from the main thread is guaranteed visible to the background writer thread reading it. Refs: RUMS-6227
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fixes a native crash reported in RUMS-6227: Android SIGSEGV inside JNI
CallObjectMethod, at a consistent/deterministic offset.The RUM/Logs event mapper (
DatadogRumEventMapper/DatadogLogEventMapper)is held in a static, process-wide singleton in
DatadogRumPlugin/DatadogLogsPlugin. It's only ever overwritten when a mapper isattached — never cleared. When a Flutter engine detaches (app
backgrounded and killed, hot restart, or Activity recreation on a
config change), that static field keeps pointing at a jnigen-generated
JNI proxy tied to the now-destroyed engine's Dart isolate.
dd-sdk-android's RUM/Logs core is itself a process-wide singleton withbackground writer/upload threads that outlive any single Flutter
engine. When one of those threads serializes a queued event and calls
into the stale mapper, it crashes inside
CallObjectMethod— ause-after-detach JNI reference, invoked from a background thread. The
deterministic crash offset is the fingerprint of this exact failure
mode (a fixed-layout call into freed memory), rather than random heap
corruption.
Change
detachFromEngine()in bothDatadogRumPluginandDatadogLogsPluginnow clears the static mapper's
eventMapperfield.DatadogRumEventMapper.eventMapper/DatadogLogEventMapper.eventMappermarked
@Volatile, so the clear is guaranteed visible to whateverbackground thread might be racing to read it.
DatadogRumPluginTest) asserting the mapperis null after
detachFromEngine().Unreleased.Testing
due to a Flutter/Gradle toolchain version mismatch unrelated to this
change (fails identically on unmodified
develop). Needs a real CI runbefore merge.
Refs: RUMS-6227
🤖 Generated with Claude Code