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.
Goal
Avoid possibly leaking tracked spans due to garbage-collection of their tokens. When a tracked span is on the
SpanContext
stack, and its "token" object (Activity
,Fragment
, etc.) is garbage-collected without the span being ended, it will remain on the stack permanently (because theSpanTracker
does not know to end it).Design
The
SpanTracker
is now implemented as a special-purposeWeakHashMap
implementation. When spans are "lost" due to their tokens being garbage collected, the spans are correctlyend
ed and removed from the table. This implementation also avoids the "map in map" design of the previousSpanTracker
by instead implementing a composite-key structure.WeakHashMap
itself is unfortunately unsuitable as we have no way to determine when entries are removed due to garbage collection.Testing
Additional unit tests