Skip to content

Prevent OkHttp connection pools from retaining request contexts - #12492

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
andrea.marziali/diag-fix-okhttp-connection-pool-context
Sep 15, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
andrea.marziali/diag-fix-okhttp-connection-pool-context

Conversation

@amarziali

Copy link
Copy Markdown
Contributor

What Does This Do

Disables generic asynchronous context propagation while OkHttp adds connections to its internal connection pools.

This covers:

  • OkHttp 2 ConnectionPool.addConnection and ConnectionPool.put
  • OkHttp 3 RealConnectionPool.put

Connection pools schedule long-lived cleanup work. Propagating the current request context into that work can retain the request trace beyond its actual lifetime.

flowchart LR
    A[Request thread<br/>request context active]
    B[ConnectionPool.put]
    C[Long-lived cleanup task]
    D[Request completes]

    A --> B
    B -->|🔴 previous: propagate request context| C
    C -->|retain until cleanup runs| L[🔴 Delayed trace completion]

    B -->|🟢 propagation disabled| C
    A --> D
    D -->|close request scope| G[🟢 Trace completes normally]
Loading

Motivation

The pool cleanup task belongs to the connection pool lifecycle, not to the request that happened to create or register the connection.

Blocking propagation at the pool boundary prevents the cleanup task from retaining an unrelated request context while preserving propagation for normal OkHttp request work.

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali amarziali added the type: bug fix Bug fix label Sep 15, 2026
@amarziali
amarziali requested review from a team as code owners September 15, 2026 07:30
@amarziali amarziali added the comp: context propagation Trace context propagation label Sep 15, 2026
@amarziali
amarziali removed the request for review from a team September 15, 2026 07:30
@amarziali amarziali added the tag: ai generated Largely based on code generated by an AI or LLM label Sep 15, 2026
@amarziali
amarziali requested review from dougqh and vandonr and removed request for a team September 15, 2026 07:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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-15T07:34:44.617379Z c88a3a8 PR opened
🔒 Security Review Completed 2026-09-15T07:34:33.053860Z c88a3a8 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-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

The new matchers cover the specified OkHttp 2, 3, and 4 pool methods. The advice restores the earlier propagation state after each call.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit c88a3a8 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@datadog-prod-us1-4

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 68.82% (+9.77%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c88a3a8 | Docs | View more details | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Sep 15, 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.83 s 14.71 s [+0.0%; +1.5%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.71 s 13.68 s [-0.6%; +1.0%] (no difference)
startup:petclinic:appsec:Agent 17.66 s 17.48 s [+0.0%; +2.0%] (maybe worse)
startup:petclinic:iast:Agent 17.60 s 17.67 s [-1.3%; +0.6%] (no difference)
startup:petclinic:profiling:Agent 17.40 s 17.31 s [-0.8%; +1.9%] (no difference)
startup:petclinic:sca:Agent 17.64 s 17.45 s [+0.1%; +2.1%] (maybe worse)
startup:petclinic:tracing:Agent 16.62 s 16.68 s [-1.4%; +0.6%] (no difference)

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

@bric3 bric3 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.

Nice improvement !

I understand it targets OKHttp 2 and 3, but could that work on later OkHttp / Okio dependencies as well ? If the signature is the same in Kotlin. Or does it need other code.

@amarziali

Copy link
Copy Markdown
Contributor Author

Nice improvement !

I understand it targets OKHttp 2 and 3, but could that work on later OkHttp / Okio dependencies as well ? If the signature is the same in Kotlin. Or does it need other code.

Yes because the enforcement I will put in place with #12458 when all the issues are solved, will enforce that leakage check. Hence future library evolutions will cause the CI to hang if drifting

@amarziali

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 09:53:41 UTC ℹ️ Start processing command /merge


2026-09-15 09:53:46 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-09-15 10:27:23 UTCMergeQueue: The build pipeline contains failing jobs for this merge request

Build pipeline has failing jobs for 916f929:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.
Details

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected and the pipeline got canceled.

@amarziali

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 10:34:55 UTC ℹ️ Start processing command /merge


2026-09-15 10:35:00 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-09-15 11:30:37 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit f9b4550 into master Sep 15, 2026
607 of 610 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the andrea.marziali/diag-fix-okhttp-connection-pool-context branch September 15, 2026 11:30
@github-actions github-actions Bot added this to the 1.67.0 milestone Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: context propagation Trace context propagation tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants