Skip to content

Fix Kotlin coroutine context loss during thread handoffs - #12951

Closed
amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/investigate-kotlin-coroutines-flake
Closed

amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/investigate-kotlin-coroutines-flake

Conversation

@amarziali

Copy link
Copy Markdown
Contributor

What Does This Do

Kotlin coroutines can resume on another worker before the previous worker restores its context. This can lose the active span and leave manual scopes unclosed.

Give each coroutine an isolated, movable scope stack so late restoration cannot overwrite newer context.

flowchart LR
  A["Worker A suspends with active scopes"]
  B["Worker B resumes using the same scope stack"]
  C["Worker A restores its previous worker context"]
  D["Worker B retains the coroutine's active scopes"]

  A --> B --> C --> D
  linkStyle 0,1,2 stroke:#289447
Loading

Add deterministic regression coverage for overlapping callbacks, nested scopes, and closed scopes staying closed.

Validation: 807 test executions passed across JDK 8 and 17, covering coroutine versions 1.3.0, 1.6.4, 1.8.1, and 1.11.0. Muzzle and formatting checks passed.

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@datadog-prod-us1-4

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.90 s 13.90 s [-0.8%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 12.78 s 12.89 s [-1.7%; -0.1%] (maybe better)
startup:petclinic:appsec:Agent 17.07 s 17.06 s [-0.8%; +1.0%] (no difference)
startup:petclinic:iast:Agent 16.97 s 17.01 s [-1.0%; +0.6%] (no difference)
startup:petclinic:profiling:Agent 16.61 s 16.76 s [-1.8%; +0.1%] (no difference)
startup:petclinic:sca:Agent 17.06 s 17.01 s [-0.5%; +1.2%] (no difference)
startup:petclinic:tracing:Agent 16.01 s 16.26 s [-2.6%; -0.5%] (maybe better)

Commit: 408e4b33 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@mcculls

mcculls commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Note my followup Kotlin PR is not yet merged - at first glance it basically does the same thing as this PR

@amarziali

Copy link
Copy Markdown
Contributor Author

closing as the linked PR is effectively not yet in master

@amarziali amarziali closed this Oct 20, 2026
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.

2 participants