Skip to content

Bound unresolved-artifact retry loop in ScaReachabilityTransformer - #12245

Open
jandro996 wants to merge 1 commit into
masterfrom
APPSEC-69734
Open

Bound unresolved-artifact retry loop in ScaReachabilityTransformer#12245
jandro996 wants to merge 1 commit into
masterfrom
APPSEC-69734

Conversation

@jandro996

@jandro996 jandro996 commented Aug 20, 2026

Copy link
Copy Markdown
Member

What Does This Do

  • Adds MAX_UNRESOLVED_RETRIES = 5 and a @VisibleForTesting final ConcurrentHashMap<String, Integer> unresolvedAttemptCounts field to ScaReachabilityTransformer.
  • In processClass(), replaces the unconditional re-queue into pendingRetransformNames with a capped one: a class whose watched artifact never resolves is retried at most MAX_UNRESOLVED_RETRIES times, then dropped with a one-time debug log.
  • Deduplicates the retry counter increment once per heartbeat per class name (via countedThisHeartbeat, cleared at the top of performPendingRetransforms()), so multiple classloaders loading the same class name in one batch consume a single attempt, not one per classloader.
  • The first-load path (transform() with classBeingRedefined == null) stays unconditional — a new class-load event (redeploy, new classloader instance) re-arms the retry window by design.
  • Documents (javadoc on unresolvedAttemptCounts) a known, accepted limitation: the counter is keyed only by class name and isn't reset per class-load lifecycle, so a class name that exhausts the cap in one classloader's lifecycle inherits the exhausted count if reloaded later under a new classloader instance. Rare in practice; not fixed.

Motivation

ScaReachabilityTransformer re-queued a class for retransformation indefinitely whenever its watched artifact could never be resolved (e.g. a dependency that isn't actually on the classpath), causing an unbounded retry loop on every heartbeat for that class.

Additional Notes

Explicit accepted trade-off: the cap is uniform for both own-JAR and classpath-wide artifact resolution, and OSGi/fat-jar apps with genuinely late-loading dependencies may lose detection after 5 heartbeats instead of retrying forever. No new configuration flag was added to disable this behavior — bounded degradation was chosen over an unbounded detection window.

Contributor Checklist

Jira ticket: APPSEC-69734

Note: Once your PR is ready to merge, add it to the merge queue by commenting /merge. /merge -c cancels the queue request. /merge -f --reason "reason" skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.

- Cap re-queue attempts for classes whose watched artifact never
  resolves via a new MAX_UNRESOLVED_RETRIES=5 limit, tracked per
  class name and deduplicated once per heartbeat.
- Document known limitation: the retry counter isn't reset per
  class-load lifecycle, so a class name reloaded after exhausting
  the cap in a discarded classloader inherits the exhausted count.
@jandro996 jandro996 added type: bug fix Bug fix comp: asm waf Application Security Management (WAF) labels Aug 20, 2026
@jandro996

Copy link
Copy Markdown
Member Author

@codex review

@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: a52dac37c1

ℹ️ 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 Aug 20, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
Patch Coverage: 91.67%
Overall Coverage: 58.58% (+0.00%)

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

@dd-octo-sts

dd-octo-sts Bot commented Aug 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.99 s 13.93 s [-0.3%; +1.1%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 13.00 s [-1.7%; +0.0%] (no difference)
startup:petclinic:appsec:Agent 16.87 s 16.71 s [+0.0%; +1.9%] (maybe worse)
startup:petclinic:iast:Agent 16.93 s 16.90 s [-0.7%; +1.0%] (no difference)
startup:petclinic:profiling:Agent 16.02 s 16.73 s [-8.3%; -0.2%] (maybe better)
startup:petclinic:sca:Agent 16.19 s 16.39 s [-5.8%; +3.3%] (no difference)
startup:petclinic:tracing:Agent 15.98 s 15.71 s [-2.6%; +6.0%] (no difference)

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

@jandro996
jandro996 marked this pull request as ready for review August 20, 2026 12:01
@jandro996
jandro996 requested a review from a team as a code owner August 20, 2026 12:01

@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 retry state uses a plain HashSet. Other agent components can start class retransformation at the same time, so concurrent add and clear operations can damage retry tracking.

Open Bits AI session

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

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

Labels

comp: asm waf Application Security Management (WAF) type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant