Skip to content

Fix context propagation for delayed Netty scheduled task - #12541

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 14 commits into
masterfrom
andrea.marziali/fix-netty-scheduled-future-context
Sep 28, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 14 commits into
masterfrom
andrea.marziali/fix-netty-scheduled-future-context

Conversation

@amarziali

@amarziali amarziali commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Fixes context propagation for delayed Netty scheduled tasks while moving the Netty-specific execution handling out of the generic RunnableFuture advice.

Starting with Netty 4.1.44, ScheduledFutureTask.run() may be called once while a delayed task is being enqueued and again when the delay expires. Activating the task scope during the enqueue-time call consumes the captured continuation, leaving no context available when the task actually executes.

For Netty versions that expose PromiseTask.runTask(), the generic RunnableFuture instrumentation no longer activates context around ScheduledFutureTask.run(). The netty-concurrent instrumentation instead
activates the existing RunnableFuture state around PromiseTask.runTask(), which is the point where the task body actually executes.

Older Netty versions without runTask() continue using the existing generic RunnableFuture.run() Instrumentation.

This approach:

  • Reuses the existing RunnableFuture -> State context store.
  • Avoids an additional marker context store.
  • Avoids polling the task delay.
  • Avoids depending on advice ordering.
  • Removes Netty-specific runtime checks from the generic advice.
  • Supports regular and shaded Netty implementations.

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali
amarziali requested review from a team as code owners September 17, 2026 07:09
@amarziali amarziali added the inst: netty Netty instrumentation label Sep 17, 2026
@amarziali
amarziali requested review from jordan-wong and sarahchen6 and removed request for a team September 17, 2026 07:09
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 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-17T09:33:18.373499Z b4c1280 Manual request
🔒 Security Review ✅ Completed 2026-09-17T09:31:33.866957Z b4c1280 Manual request
ℹ️ 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.

@amarziali amarziali changed the title Move scheduled Netty task handling to Netty instrumentation Fix context propagation for delayed Netty scheduled task Sep 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24279fbd2a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-official

This comment has been minimized.

@amarziali
amarziali marked this pull request as draft September 17, 2026 07:28

@datadog-official datadog-official 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.

Datadog Autotest: FAIL

The new matcher has no Netty bytecode reference. Unsupported versions pass Muzzle validation, so the inverse compatibility task fails and blocks CI.

Open Bits AI session

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

@dd-octo-sts

dd-octo-sts Bot commented Sep 17, 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.07 s 14.02 s [-0.3%; +1.1%] (no difference)
startup:insecure-bank:tracing:Agent 12.97 s 13.08 s [-1.6%; -0.1%] (maybe better)
startup:petclinic:appsec:Agent 17.10 s 16.94 s [-0.0%; +1.8%] (no difference)
startup:petclinic:iast:Agent 16.95 s 16.47 s [-1.6%; +7.4%] (no difference)
startup:petclinic:profiling:Agent 16.62 s 16.94 s [-3.1%; -0.7%] (maybe better)
startup:petclinic:sca:Agent 16.98 s 16.88 s [-0.5%; +1.6%] (no difference)
startup:petclinic:tracing:Agent 16.20 s 16.21 s [-1.2%; +1.2%] (no difference)

Commit: f6f1f447 · 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

@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

@datadog-official datadog-official 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.

Datadog Autotest: PASS

More details

Netty 4.1.44 and later keep the captured context until runTask() starts. Older Netty versions continue to activate the context in RunnableFuture.run().

Was this helpful? React 👍 or 👎

Open Bits AI session

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: a5ba81ce3d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5ba81ce3d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@amarziali
amarziali marked this pull request as ready for review September 17, 2026 08:52

@datadog-official datadog-official 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.

Datadog Autotest: PASS

More details

Regular and shaded delayed tasks retain context at execution time. Older Netty tasks keep the existing run path.

Was this helpful? React 👍 or 👎

Open Bits AI session

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

@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 3a9cabf941

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a9cabf941

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@amarziali

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: b4c1280db6

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: b4c1280db6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Left a small comment about scope but otherwise looks reasonable to me!

btw - looks like the failing CI jobs can be fixed by adding

testImplementation project(':dd-java-agent:instrumentation:netty:netty-concurrent-4.0')

to dd-java-agent/instrumentation/armeria/armeria-grpc-0.84/build.gradle. Seems like Armeria's use of java-concurrent now depend on NettyPromiseTaskInstrumentation and require netty-concurrent-4.0..... "Armeria’s tests load java-concurrent, which still captures continuations when Netty scheduled tasks are constructed. This PR makes that instrumentation skip ScheduledFutureTask.run(). So, Activation and release now depend on NettyPromiseTaskInstrumentation in netty-concurrent-4.0."

Keep the task scope active until ScheduledFutureTask.run() exits, including
success and failure listeners. Cover nested activation and scope cleanup.

Add the Netty concurrent test dependency required by Armeria gRPC tests.
@amarziali
amarziali force-pushed the andrea.marziali/fix-netty-scheduled-future-context branch from 112148d to ab033b9 Compare September 22, 2026 10:07

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD 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.

LGTM, but probably lock-files should be regenerated before merge.
Minor note: tests kind-of-hard to read for human... Maybe worth adding some comments explaining what test is doing?

@amarziali

Copy link
Copy Markdown
Contributor Author

Minor note: tests kind-of-hard to read for human... Maybe worth adding some comments explaining what test is doing?

No worries I added more comments in 949a8bb

@jordan-wong jordan-wong 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.

claude caught this, this looks somewhat significant as it breaks the purposes of the forked tests, other than that would give LGTM

@amarziali
amarziali enabled auto-merge September 25, 2026 07:12
@amarziali
amarziali added this pull request to the merge queue Sep 28, 2026
@dd-octo-sts

dd-octo-sts Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-28 08:07:58 UTC ℹ️ Start processing command /merge


2026-09-28 08:08:03 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-09-28 09:11:25 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 28, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit c30e496 into master Sep 28, 2026
606 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the andrea.marziali/fix-netty-scheduled-future-context branch September 28, 2026 09:11
@github-actions github-actions Bot added this to the 1.67.0 milestone Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants