Skip to content

Fix Hystrix async error tests without relaxing trace validation - #12570

Open
amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/fix-hystrix-rxjava-scope-cleanup
Open

amarziali wants to merge 1 commit into
masterfrom
andrea.marziali/fix-hystrix-rxjava-scope-cleanup

Conversation

@amarziali

@amarziali amarziali commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Fix intermittent Hystrix observable test timeouts while retaining RxJava 1.0.7 coverage and enabling strict trace writes in both observable test suites.

Why the tests were failing

RxJava 1.0.7 has a race in observeOn error handling that can leave its worker spinning inside OperatorObserveOn.pollQueue().

The error is stored as a notification in the same queue as ordinary values. The following interleaving can occur:

  1. The worker enters the normal queue-draining path.
  2. The producer publishes an error.
  3. The worker consumes and delivers that error through the normal path, which does not return after delivering a terminal notification.
  4. On the next iteration, the worker enters the error-draining path and searches for the error notification it already consumed.

This explains the seemingly contradictory symptoms: Hystrix delivers its fallback and the spans finish, but the asynchronous task never returns.

The task’s tracing scope consequently remains open, retaining its continuation. Strict trace writes wait for that continuation to be released, and the trace assertion eventually times out.

sequenceDiagram
    participant P as Producer
    participant W as RxJava worker
    participant H as Hystrix
    participant T as Trace lifecycle

    W->>W: Enter normal drain path
    P->>W: Enqueue error notification
    W->>H: Consume and deliver error
    H->>H: Execute fallback and finish spans
    W->>W: Enter error path
    loop Error notification already consumed
        W->>W: Poll queue
    end
    Note over W,T: Task never returns. scope and continuation remain open
    T->>T: Strict trace assertion times out
Loading

The continuation diagnostic exposed the unfinished task; it was not itself causing the failure. An agent-free reproducer exhibited the same loop on RxJava 1.0.7. Replacing first() with single() also reproduced the hang, so merely waiting for downstream completion was insufficient.

What changed

For the baseline error-producing fixtures, transport the error across the scheduler as an ordinary notification:

source.materialize()
  .observeOn(scheduler)
  .dematerialize()

materialize() converts the error into a value, avoiding the broken observeOn error-draining path. dematerialize() restores the error on the scheduler thread before Hystrix receives it.

Coverage tradeoff

The baseline fixtures still run against RxJava 1.0.7, but deliberately avoid its defective native error-draining path. Direct-path coverage remains in the latest-dependency suite.

This avoids upgrading away from the baseline version, weakening trace assertions, or adding production instrumentation to repair an upstream library bug.

Motivation

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@amarziali
amarziali requested a review from a team as a code owner September 18, 2026 15:59
@amarziali
amarziali requested review from ValentinZakharov and removed request for a team September 18, 2026 15:59
@amarziali amarziali added type: bug fix Bug fix comp: testing Testing tag: no release notes Changes to exclude from release notes labels Sep 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 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-18T16:01:33.351795Z 3f85073 PR opened
🔒 Security Review Completed 2026-09-18T16:02:12.314982Z 3f85073 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-3 datadog-prod-us1-3 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 workaround applies only to baseline RxJava 1.0.7 error paths. The latest-dependency suite keeps direct observeOn coverage and strict trace writes.

Was this helpful? React 👍 or 👎

Open Bits AI session

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

@datadog-prod-us1-3

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Sep 18, 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.87 s 14.71 s [+0.2%; +1.9%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.63 s 13.72 s [-1.5%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 17.51 s 16.63 s [+1.0%; +9.6%] (maybe worse)
startup:petclinic:iast:Agent 17.39 s 16.96 s [-1.8%; +6.9%] (no difference)
startup:petclinic:profiling:Agent 17.44 s 17.15 s [+0.5%; +3.0%] (maybe worse)
startup:petclinic:sca:Agent 17.52 s 17.44 s [-0.5%; +1.4%] (no difference)
startup:petclinic:tracing:Agent 16.51 s 16.71 s [-2.1%; -0.3%] (maybe better)

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

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

Labels

comp: testing Testing tag: no release notes Changes to exclude from release notes type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant