Skip to content

fix(runtime): keep span async slice begin/end ordered; release 0.1.0-ALPHA03 - #172

Merged
santimattius merged 2 commits into
mainfrom
fix/span-async-section-ordering
Nov 2, 2026
Merged

santimattius merged 2 commits into
mainfrom
fix/span-async-section-ordering

Conversation

@santimattius

Copy link
Copy Markdown
Owner

Summary

Fixes a concurrency bug in the span:<name> async slice that AndroidTraceSink emits (#169), and bumps the runtime family to 0.1.0-ALPHA03.

Bug: the span transition (map update) and the matching beginAsyncSection/endAsyncSection call were two separate steps. Under concurrency a Started could overtake a Finished and emit begin, begin, end on the same cookie, so Perfetto showed only the first part of the span.

Evidence (Android 15 emulator, PoC android-coroutine-storm, unbounded scenario, 2000 dispatches over ~1.3 s):

  • With 0.1.0-ALPHA02: the span appears as 3 slices covering ~110 ms.
  • With this fix (runtime published to Maven local): 6 contiguous slices covering the whole ~1.37 s window.

Fix: run the map transition and the trace call inside one atomic per-key operation (compute/computeIfPresent), so begin/end strictly alternate. Trace-API failures are swallowed inside it so state stays consistent.

Known limitation (unchanged, documented)

A span is still drawn as several consecutive slices when no segment of it is running for a moment (gaps under 1 ms in the trace above).

Test plan

./gradlew :runtime:jvmTest :runtime:apiCheck :runtime-tracing:jvmTest :runtime-tracing:apiCheck

New multi-threaded regression test concurrentSegmentsOfOneSpanAlternateBeginAndEndStrictly (8 threads x 5000 start/finish pairs). It failed before the fix (224 out-of-order transitions in one run) and passes now, 5 forced reruns. No public API change.

Relates to #168

The span transition and the matching beginAsyncSection/endAsyncSection call
were two steps, so a concurrent Started could overtake a Finished and emit
begin, begin, end on the same cookie. Perfetto then showed only the first
part of the span. Run both inside one atomic per-key operation and add a
multi-threaded regression test.
Bump RUNTIME_VERSION to 0.1.0-ALPHA03 and update the install snippets in
the runtime READMEs and the changelog.
@santimattius
santimattius merged commit 8bf229b into main Nov 2, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant