Skip to content

Fix context propagation for delayed Netty scheduled task - #12541

Open
amarziali wants to merge 5 commits into
masterfrom
andrea.marziali/fix-netty-scheduled-future-context
Open

amarziali wants to merge 5 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

datadog-official Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 59.03% (-0.07%)

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

@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.82 s 14.68 s [+0.1%; +1.9%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.57 s 13.75 s [-2.2%; -0.5%] (maybe better)
startup:petclinic:appsec:Agent 17.00 s 16.77 s [-4.9%; +7.6%] (unstable)
startup:petclinic:iast:Agent 17.28 s 17.53 s [-2.2%; -0.6%] (maybe better)
startup:petclinic:profiling:Agent 17.44 s 16.63 s [+0.5%; +9.2%] (maybe worse)
startup:petclinic:sca:Agent 17.52 s 17.35 s [+0.0%; +2.0%] (maybe worse)
startup:petclinic:tracing:Agent 16.48 s 16.60 s [-1.8%; +0.3%] (no difference)

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

: null;
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)

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.

from Codex review and seems reasonable to me - this closes the scope when runTask() returns or throws. Netty subsequently calls setSuccessInternal() or setFailureInternal(), which notify completion listeners. Those callbacks now execute after the scheduling context has been removed. - so it seems like we can lose span context / disconnect traces here

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.

2 participants