Skip to content

Prevent JDK virtual I/O threads from retaining request context - #12626

Open
amarziali wants to merge 3 commits into
masterfrom
andrea.marziali/fix-jdk-poller-context
Open

amarziali wants to merge 3 commits into
masterfrom
andrea.marziali/fix-jdk-poller-context

Conversation

@amarziali

Copy link
Copy Markdown
Contributor

What Does This Do

Prevent long-lived JDK infrastructure threads from inheriting the request that happens to create them:

  • Start virtual I/O pollers under root context, restoring the caller’s context afterward.
  • Exclude the JDK HTTP client’s internal selector task from virtual-thread context capture.
  • Preserve propagation for ordinary application virtual threads.

Motivation

irst-use initialization under an active request could capture that request in permanent SubPoller threads. JDK 26’s virtual HTTP selector could also retain its creating request for the client’s lifetime.

These threads do not belong to the request, and their continuations cannot be released until they terminate. The smoke-test continuation diagnostic exposed both paths.

Simply disabling async capture is insufficient: virtual-thread instrumentation also saves the raw context independently.

flowchart TD
    A[Active request] --> B[Create HTTP client]
    B --> C[Virtual selector]
    C --> D[Initialize shared I/O pollers]
    D --> E[Permanent virtual pollers]

    C -. Before: retains request .-> F[Request context and continuation]
    E -. Before: retains request .-> F

    C --> G[After: no inherited request]
    D --> H[After: initialize under root context]

    style F fill:#ffdddd,stroke:#cc3333
    style G fill:#ddffdd,stroke:#339933
    style H fill:#ddffdd,stroke:#339933
Loading

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali
amarziali requested review from a team as code owners September 24, 2026 07:40
@amarziali amarziali added the type: bug fix Bug fix label Sep 24, 2026
@amarziali
amarziali removed the request for review from a team September 24, 2026 07:40
@amarziali amarziali added the inst: java Core Java language instrumentation label Sep 24, 2026
@amarziali
amarziali requested a review from bric3 September 24, 2026 07:40
@amarziali amarziali added the tag: concurrency Virtual Threads, Coroutines, Async, RX, Executors label Sep 24, 2026
@amarziali
amarziali requested review from jordan-wong and removed request for a team September 24, 2026 07:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T07:44:30.364300Z 99ccea5 PR opened
🔒 Security Review ✅ Completed 2026-09-24T07:44:26.740297Z 99ccea5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1

This comment has been minimized.

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The two most critical issues are a production memory-retention bug in PollerInstrumentation where request context leaks into long-lived poller threads when the scope-depth limit is reached, and a test compatibility failure in PollerContextForkedTest that throws NoSuchFieldException on JDK 22 due to a missing POLLERS field.

Open Bits AI session

🤖 Bits Code Review · Commit 99ccea5 · @DataDog review to ask questions

@dd-octo-sts

dd-octo-sts Bot commented Sep 24, 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 14.00 s 14.00 s [-0.8%; +0.7%] (no difference)
startup:insecure-bank:tracing:Agent 12.94 s 13.03 s [-1.3%; +0.0%] (no difference)
startup:petclinic:appsec:Agent 17.07 s 16.90 s [+0.1%; +2.1%] (maybe worse)
startup:petclinic:iast:Agent 16.96 s 17.01 s [-1.1%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 16.77 s 16.83 s [-1.3%; +0.5%] (no difference)
startup:petclinic:sca:Agent 16.32 s 16.81 s [-7.1%; +1.3%] (no difference)
startup:petclinic:tracing:Agent 16.18 s 16.11 s [-0.4%; +1.3%] (no difference)

Commit: b5dcae4f · 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.

@amarziali

Copy link
Copy Markdown
Contributor Author

@DataDog review

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The JDK poller and HTTP selector paths no longer retain a request context. Application virtual threads still propagate the request context.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b5dcae4 · @DataDog review to ask questions

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: java Core Java language instrumentation tag: concurrency Virtual Threads, Coroutines, Async, RX, Executors type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant