← Back to Pull requests

fix(fastify): bound error-channel recursion and stop swallowing async hook rejections #9118

Merged
BridgeAR merged 4 files (151 lines) on Jul 06, 2026 18:21 UTC
View on GitHub
BridgeAR BridgeAR commented on Jun 27, 2026 20:29 UTC
Author

Summary

Fastify boots through avvio, whose _encapsulateThreeParam re-invokes an encapsulated hook after it throws. The same error object rides every re-drive, and the wrapped hook republishes it on apm:fastify:middleware:error each time. The in-flight boolean added in #8788 only blocks a publish nested inside another publish; a sequential re-drive runs after the publish returned and its finally cleared the flag, so every re-drive publishes again, the channel subscriber recurses, and boot dies with RangeError: Maximum call stack size exceeded. A persistent DatadogRaspAbortError (appsec RASP) or the boot deprecation warning is the error that rides the loop.

1. createErrorPublisher keeps the boolean for nested re-entry and adds a WeakSet keyed on the error object, so the same error publishes at most once per channel — bounding the sequential re-drive a boolean cannot. A genuinely distinct error still reaches subscribers; the entry frees once the error object is unreachable.
2. invokeHookWithContext's async branch returned publishError(ctx) (i.e. ctx.error) from the .catch handler, which resolves the promise with the error and silently swallows the rejection. It now publishes and re-throws so the rejection keeps propagating. The synchronous branch is decoupled the same way: publish, then throw the original error rather than the publisher's return value.

Why

The error channel's two subscribers — the router plugin's web.addError (tag the request span once) and appsec RASP's block (block the response once) — both want once-per-error cardinality, so keying the guard on the error object matches what they need. The residual trade-off is that the same error object reaching the channel through two genuinely distinct contexts publishes once; that is exactly the recursion being bounded, and once-per-error is the correct cardinality for both subscribers.

The real avvio re-drive needs a specific plugin/encapsulation arrangement from the reporter's app that I could not reconstruct, so the regression pins the precise invariant at the real seam instead: the real wrapped hook, driven the way avvio drives a re-thrown hook, publishes a persistent error exactly once across thousands of re-drives (fails on master with one publish per re-drive), a distinct error still publishes each time, and a rejecting async hook re-rejects instead of resolving-with-error.

Test plan

  • packages/datadog-instrumentations/test/fastify.spec.js (exercised by the instrumentation-fastify CI job): the three added/changed cases fail on master and pass here.

  • Sibling frameworks that share createErrorPublisher (koa, connect, restify, router) — instrumentation specs stay green.
  • Fixes: https://github.com/DataDog/dd-trace-js/issues/9099
    Refs: https://github.com/DataDog/dd-trace-js/issues/8783

    Diff: 151 lines (+141 / -10) across 4 files Reviewer: crysmags Review duration: 12832m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.37) × (1 − Review Confidence (0.73)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 151 lines diff across 4 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.48 · 5 substantive comment(s)
    0.48
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    72%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.301
    Real PR Conversation Timeline
    10 items
    dd-octo-sts[bot] dd-octo-sts[bot] commented on Jun 27, 2026 20:30 UTC
    Bot

    Overall package size

    Self size: 6.53 MB
    Deduped: 7.59 MB
    No deduping: 7.59 MB

    <details><summary>Dependency sizes</summary>
    | name | version | self size | total size |
    |------|---------|-----------|------------|
    | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 kB |
    | opentracing | 0.14.7 | 194.81 kB | 194.81 kB |
    | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

    </details>

    <sub>🤖 This report was automatically generated by heaviest-objects-in-the-universe<sub>

    datadog-datadog-prod-us1[bot] datadog-datadog-prod-us1[bot] commented on Jun 27, 2026 20:31 UTC
    Bot

    <picture><source media="(prefers-color-scheme: dark)" srcset="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/tests-ok.svg"/><img src="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/tests-ok-light.svg" alt="Tests" align="center" /></picture>

    <details><summary><b>🎉 All green!</b></summary>

    🧪 All tests passed
    ❄️ No new flaky tests detected
    </details>

    🎯 Code Coverage (<a target='_blank' href='https://app.datadoghq.com/ci/code-coverage/github.com%2Fdatadog%2Fdd-trace-js/pull-requests/9118'>details</a>)<br>• <strong><span title="Percentage of modified executable lines covered by tests in this PR">Patch Coverage</span></strong>: 100.00%<br>• <strong><span title="Percentage of all executable lines covered by tests in the entire codebase">Overall Coverage</span></strong>: 87.86% <span title="Change in overall coverage compared to the base branch">(-0.13%)</span><br>

    <sub>
    This comment will be updated automatically if new data arrives. <br />
    🔗 Commit SHA: a7a0b06 | <a href="https://docs.datadoghq.com/integrations/guide/source-code-integration/#pr-comments">Docs</a> | <a href="https://app.datadoghq.com/ci/pull-request/Z2l0aHViLmNvbS9kYXRhZG9nL2RkLXRyYWNlLWpzLzkxMTg=">Datadog PR Page</a> | Give us <a href="https://dd.enterprise.slack.com/archives/C07E3U2QRMM">feedback</a>!
    </sub>

    codecov[bot] codecov[bot] commented on Jun 27, 2026 20:39 UTC
    Bot

    Codecov Report


    :white_check_mark: All modified and coverable lines are covered by tests.
    :white_check_mark: Project coverage is 93.64%. Comparing base (27dcc31) to head (a7a0b06).
    :warning: Report is 39 commits behind head on master.

    <details><summary>Additional details and impacted files</summary>

    @@            Coverage Diff             @@
    ##           master    #9118      +/-   ##
    ==========================================
    - Coverage   93.69%   93.64%   -0.05%     
    ==========================================
      Files         889      898       +9     
      Lines       50856    52370    +1514     
      Branches    11830    12325     +495     
    ==========================================
    + Hits        47647    49042    +1395     
    - Misses       3209     3328     +119     
    

    | Flag | Coverage Δ | |
    |---|---|---|
    | aiguard | 34.88% <ø> (-0.08%) | :arrow_down: |
    | aiguard-integration | 41.96% <ø> (+0.17%) | :arrow_up: |
    | apm-bucket-0 | 34.84% <ø> (-0.08%) | :arrow_down: |
    | apm-bucket-1 | 40.51% <ø> (+0.09%) | :arrow_up: |
    | apm-bucket-2 | 37.50% <ø> (+0.08%) | :arrow_up: |
    | apm-capabilities-tracing | 48.88% <ø> (+0.59%) | :arrow_up: |
    | apm-integrations-aerospike | 33.13% <ø> (-0.08%) | :arrow_down: |
    | apm-integrations-confluentinc-kafka-javascript | 40.12% <ø> (+0.01%) | :arrow_up: |
    | apm-integrations-couchbase | 33.41% <ø> (-0.19%) | :arrow_down: |
    | apm-integrations-http | 42.05% <ø> (-0.06%) | :arrow_down: |
    | apm-integrations-kafkajs | 40.27% <ø> (-0.08%) | :arrow_down: |
    | apm-integrations-next | 29.63% <ø> (+0.05%) | :arrow_up: |
    | apm-integrations-prisma | 35.18% <ø> (+0.07%) | :arrow_up: |
    | apm-integrations-tedious | 34.05% <ø> (+0.07%) | :arrow_up: |
    | appsec | 57.90% <ø> (+0.46%) | :arrow_up: |
    | appsec-express_fastify_graphql | 53.87% <63.63%> (+0.06%) | :arrow_up: |
    | appsec-integration | 35.68% <0.00%> (-0.58%) | :arrow_down: |
    | appsec-kafka_ldapjs_lodash | 43.83% <ø> (+0.17%) | :arrow_up: |
    | appsec-mongodb-core_mongoose_mysql | 48.93% <ø> (+0.05%) | :arrow_up: |
    | appsec-next | 28.11% <ø> (+0.04%) | :arrow_up: |
    | appsec-node-serialize_passport_postgres | 48.08% <ø> (+0.02%) | :arrow_up: |
    | appsec-sourcing_stripe_template | 45.64% <ø> (+0.01%) | :arrow_up: |
    | debugger | 44.62% <0.00%> (+0.20%) | :arrow_up: |
    | instrumentations-bucket-0 | 28.17% <ø> (-0.07%) | :arrow_down: |
    | instrumentations-bucket-1 | 37.57% <ø> (+0.08%) | :arrow_up: |
    | instrumentations-bucket-10 | 40.52% <ø> (+0.01%) | :arrow_up: |
    | instrumentations-bucket-11 | 27.96% <ø> (-0.07%) | :arrow_down: |
    | instrumentations-bucket-12 | 28.79% <ø> (+0.04%) | :arrow_up: |
    | instrumentations-bucket-13 | 27.79% <ø> (-0.07%) | :arrow_down: |
    | instrumentations-bucket-2 | 30.36% <ø> (+0.05%) | :arrow_up: |
    | instrumentations-bucket-3 | 36.06% <ø> (+0.07%) | :arrow_up: |
    | instrumentations-bucket-4 | 28.60% <100.00%> (+0.45%) | :arrow_up: |
    | instrumentations-bucket-5 | 36.42% <ø> (+0.07%) | :arrow_up: |
    | instrumentations-bucket-6 | 38.43% <ø> (+0.09%) | :arrow_up: |
    | instrumentations-bucket-7 | 36.15% <0.00%> (+0.07%) | :arrow_up: |
    | instrumentations-bucket-8 | 37.11% <ø> (+0.08%) | :arrow_up: |
    | instrumentations-bucket-9 | 39.62% <ø> (+0.01%) | :arrow_up: |
    | instrumentations-instrumentation-couchbase | 46.48% <ø> (-0.07%) | :arrow_down: |
    | instrumentations-integration-esbuild | 24.51% <0.00%> (-0.37%) | :arrow_down: |
    | llmobs-ai_anthropic_bedrock | 39.68% <ø> (+0.08%) | :arrow_up: |
    | llmobs-google-genai_langchain_vertex-ai | 37.10% <ø> (+0.06%) | :arrow_up: |
    | llmobs-openai | 39.74% <ø> (+0.09%) | :arrow_up: |
    | llmobs-sdk | 43.59% <ø> (-0.10%) | :arrow_down: |
    | master-coverage | 93.64% <100.00%> (?) | |
    | openfeature | 37.94% <ø> (+0.17%) | :arrow_up: |
    | openfeature-unit | 50.47% <ø> (+0.07%) | :arrow_up: |
    | platform-core_esbuild_instrumentations-misc | 22.96% <0.00%> (-0.41%) | :arrow_down: |
    | platform-integration | 47.58% <0.00%> (+0.15%) | :arrow_up: |
    | platform-shimmer_unit-guardrails_webpack | 18.47% <0.00%> (-0.42%) | :arrow_down: |
    | plugins-bucket-0 | 36.52% <ø> (+0.12%) | :arrow_up: |
    | plugins-bucket-1 | 39.78% <ø> (+0.17%) | :arrow_up: |
    | plugins-bucket-11 | 38.63% <ø> (+0.09%) | :arrow_up: |
    | plugins-bucket-17 | 39.22% <ø> (-0.01%) | :arrow_down: |
    | plugins-bucket-18 | 42.17% <ø> (+0.09%) | :arrow_up: |
    | plugins-bucket-19 | 39.73% <ø> (+0.09%) | :arrow_up: |
    | plugins-bucket-20 | 43.44% <ø> (+0.07%) | :arrow_up: |
    | plugins-bucket-4 | 37.90% <81.81%> (+0.10%) | :arrow_up: |
    | plugins-bullmq_cassandra_cookie | 39.93% <ø> (+0.09%) | :arrow_up: |
    | plugins-cookie-parser_crypto_dd-trace-api | 33.23% <ø> (-0.08%) | :arrow_down: |
    | plugins-fetch_fs_generic-pool | 36.21% <ø> (+0.08%) | :arrow_up: |
    | plugins-google-cloud-pubsub_grpc_handlebars | 43.09% <ø> (-0.10%) | :arrow_down: |
    | plugins-hapi_hono_ioredis | 37.95% <ø> (+0.08%) | :arrow_up: |
    | plugins-jest_knex_langgraph | 32.61% <ø> (-0.08%) | :arrow_down: |
    | plugins-ldapjs_light-my-request_limitd-client | 27.86% <ø> (-0.07%) | :arrow_down: |
    | plugins-lodash_mariadb_memcached | 35.18% <ø> (-0.08%) | :arrow_down: |
    | plugins-mongodb_mongodb-core_mongoose | 36.46% <ø> (+0.08%) | :arrow_up: |
    | plugins-multer_mysql_mysql2 | 35.15% <ø> (-0.08%) | :arrow_down: |
    | plugins-nats_node-serialize_opensearch | 37.31% <ø> (+0.08%) | :arrow_up: |
    | plugins-passport-http_pino_postgres | 35.53% <ø> (-0.08%) | :arrow_down: |
    | plugins-process_pug_redis | 34.27% <ø> (-0.08%) | :arrow_down: |
    | plugins-undici_url_valkey | 36.04% <ø> (+0.08%) | :arrow_up: |
    | plugins-vm_winston_ws | 37.72% <ø> (+0.08%) | :arrow_up: |
    | profiling | 43.81% <ø> (+0.12%) | :arrow_up: |
    | serverless-aws-sdk-aws-sdk | 33.32% <ø> (-0.05%) | :arrow_down: |
    | serverless-aws-sdk-bedrockruntime | 32.19% <ø> (-0.04%) | :arrow_down: |
    | serverless-aws-sdk-client | 37.16% <ø> (-0.05%) | :arrow_down: |
    | serverless-aws-sdk-dynamodb | 34.14% <ø> (-0.09%) | :arrow_down: |
    | serverless-aws-sdk-eventbridge | 27.36% <ø> (+0.04%) | :arrow_up: |
    | serverless-aws-sdk-kinesis | 37.55% <ø> (+0.07%) | :arrow_up: |
    | serverless-aws-sdk-lambda | 34.64% <ø> (-0.03%) | :arrow_down: |
    | serverless-aws-sdk-s3 | 32.63% <ø> (-0.04%) | :arrow_down: |
    | serverless-aws-sdk-serverless-peer-service | 39.74% <ø> (+0.19%) | :arrow_up: |
    | serverless-aws-sdk-sns | 38.40% <ø> (-0.05%) | :arrow_down: |
    | serverless-aws-sdk-sqs | 38.14% <ø> (+0.07%) | :arrow_up: |
    | serverless-aws-sdk-stepfunctions | 33.22% <ø> (-0.04%) | :arrow_down: |
    | serverless-aws-sdk-util | 47.95% <ø> (ø) | |
    | serverless-bucket-0 | 39.64% <ø> (+0.17%) | :arrow_up: |
    | serverless-lambda | 34.34% <ø> (-0.08%) | :arrow_down: |
    | test-optimization-cucumber | 52.54% <ø> (+0.08%) | :arrow_up: |
    | test-optimization-cypress | 49.63% <ø> (+0.07%) | :arrow_up: |
    | test-optimization-jest | 55.61% <ø> (+0.04%) | :arrow_up: |
    | test-optimization-mocha | 53.65% <ø> (+0.07%) | :arrow_up: |
    | test-optimization-playwright-playwright-atr | 43.53% <ø> (+0.03%) | :arrow_up: |
    | test-optimization-playwright-playwright-efd | 43.81% <ø> (+0.02%) | :arrow_up: |
    | test-optimization-playwright-playwright-final-status | 43.94% <ø> (+0.09%) | :arrow_up: |
    | test-optimization-playwright-playwright-impacted-tests | 43.36% <ø> (-0.06%) | :arrow_down: |
    | test-optimization-playwright-playwright-reporting | 43.47% <ø> (+0.06%) | :arrow_up: |
    | test-optimization-playwright-playwright-test-management | 44.93% <ø> (+0.08%) | :arrow_up: |
    | test-optimization-playwright-playwright-test-span | 44.71% <ø> (+<0.01%) | :arrow_up: |
    | test-optimization-selenium | 45.44% <ø> (-0.02%) | :arrow_down: |
    | test-optimization-testopt | 46.82% <ø> (-1.38%) | :arrow_down: |
    | test-optimization-vitest | 52.71% <ø> (+1.88%) | :arrow_up: |

    Flags with carried forward coverage won't be shown. Click here to find out more.
    </details>

    :umbrella: View full report in Codecov by Harness.
    :loudspeaker: Have feedback on the report? Share it here.
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

  • </details>

    pr-commenter[bot] pr-commenter[bot] commented on Jun 27, 2026 20:41 UTC
    Bot

    Benchmarks

    Benchmark execution time: 2026-07-02 16:48:28

    Comparing candidate commit a7a0b06fd2414dda85112ed5ab651799fa9022a1 in PR branch BridgeAR/2026-06-27-fastify-error-recursion with baseline commit 27dcc31908d9a6264b1536a2118534c8bc4da0f6 in branch master.

    📊 Benchmarking dashboard

    Found 0 performance improvements and 0 performance regressions! Performance is the same for 2255 metrics, 31 unstable metrics.

    <details>
    <summary><h3>Explanation</h3></summary>

    This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

    🟩 = significantly better candidate vs. baseline
    🟥 = significantly worse candidate vs. baseline

    We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

    If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

    Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

    <details>
    <summary><h4>More details about the CI and significant changes</h4></summary>

    You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

    CIs of the difference of means are often centered around 0%, because often changes are not that big:

    ---------------------------------(------|---^--------)-------------------------------->
                                  -0.6%    0%  0.3%     +1.2%
                                     |          |        |
             lower bound of the CI --'          |        |
    sample mean (center of the CI) -------------'        |
             upper bound of the CI ----------------------'
    

    As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

    For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

    ----------------------------------------|---------|---(---------^---------)---------->
                                           0%        1%  1.3%      2.2%      3.1%
                                                      |   |         |         |
           significant impact threshold --------------'   |         |         |
                          lower bound of CI --------------'         |         |
           sample mean (center of the CI) --------------------------'         |
                          upper bound of CI ----------------------------------'
    

    </details>

    </details>

    <details>
    <summary><h3>Unstable benchmarks</h3></summary>

    These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

    scenario:appsec-appsec-enabled-24

  • unstable execution_time [-180.721ms; +177.575ms] or [-6.875%; +6.755%]
  • scenario:appsec-appsec-enabled-26

  • unstable execution_time [-207094.281µs; +208003.914µs] or [-8.228%; +8.264%]
  • scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-160908.933µs; +159687.733µs] or [-5.589%; +5.546%]
  • scenario:appsec-control-20

  • unstable execution_time [-162478.433µs; +161457.733µs] or [-9.302%; +9.243%]
  • scenario:appsec-control-24

  • unstable execution_time [-93.059ms; +109.544ms] or [-7.697%; +9.061%]
  • scenario:appsec-control-26

  • unstable execution_time [-112078.223µs; +111239.023µs] or [-9.283%; +9.214%]
  • scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-2747.596ms; +2665.536ms] or [-32.304%; +31.340%]

  • unstable execution_time [-2746.021ms; +2700.315ms] or [-29.864%; +29.367%]

  • unstable instructions [-23019.1M instructions; +22709.8M instructions] or [-33.176%; +32.731%]

  • unstable max_rss_usage [-9735.510KB; +9230.710KB] or [-6.065%; +5.751%]

  • unstable throughput [-786.657op/s; +804.991op/s] or [-21.456%; +21.956%]
  • scenario:debugger-line-probe-with-snapshot-default-26

  • unstable cpu_user_time [-2975.823ms; +3020.942ms] or [-29.679%; +30.129%]

  • unstable execution_time [-3060.975ms; +3090.904ms] or [-28.553%; +28.832%]

  • unstable instructions [-26096.2M instructions; +26253.8M instructions] or [-31.173%; +31.361%]

  • unstable max_rss_usage [-9026.207KB; +9452.607KB] or [-5.620%; +5.886%]

  • unstable throughput [-663.566op/s; +651.885op/s] or [-21.208%; +20.835%]
  • scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-2981.413ms; +2853.203ms] or [-29.947%; +28.659%]

  • unstable execution_time [-3018.477ms; +2875.880ms] or [-28.338%; +26.999%]

  • unstable instructions [-26567.1M instructions; +25709.9M instructions] or [-31.856%; +30.828%]

  • unstable max_rss_usage [-8549.277KB; +9955.677KB] or [-5.336%; +6.214%]

  • unstable throughput [-630.092op/s; +676.626op/s] or [-20.062%; +21.544%]
  • scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-3.253s; +0.429s] or [-32.318%; +4.262%]

  • unstable execution_time [-3.288s; +0.436s] or [-30.553%; +4.048%]

  • unstable instructions [-29.2G instructions; +3.6G instructions] or [-34.607%; +4.221%]

  • unstable throughput [-90.562op/s; +697.746op/s] or [-2.886%; +22.239%]
  • scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-302.240ms; +379.983ms] or [-6.038%; +7.591%]

  • unstable execution_time [-305.728ms; +378.548ms] or [-6.017%; +7.451%]

  • unstable throughput [-129971.856op/s; +104517.820op/s] or [-7.865%; +6.325%]
  • scenario:plugin-graphql-long-with-depth-and-collapse-off-20

  • unstable max_rss_usage [-16.716MB; +29.830MB] or [-4.530%; +8.085%]
  • scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable max_rss_usage [-59.440MB; +79.340MB] or [-25.525%; +34.071%]
  • scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-6.130MB; +2.816MB] or [-7.572%; +3.479%]
  • </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Jun 28, 2026 00:33 UTC
    Code Review
    packages/datadog-instrumentations/src/fastify.js:1
    @@ -305,11 +310,19 @@ function getRouteConfig (request) {
     }
     
     function publishError (ctx) {
    -  if (ctx.error) {
    -    publishErrorChannel(ctx)
    -  }
    -
    -  return ctx.error
    +  const error = ctx.error
    +  if (!error) return
    +
    +  // avvio's boot loop (`_encapsulateThreeParam`) re-invokes the same encapsulated
    +  // hook after it throws, re-throwing the same error object on every re-drive
    +  // (#9099). Each re-drive is sequential, so the channel's in-flight flag has
    +  // already reset; the re-drive carries the one caught error on every hop, so a
    +  // reference compare against the previously published error terminates the loop
    +  // before the subscriber recurses and boot overflows the stack.
    +  if (error === lastPublishedError) return

    <sub><sub>!P2 Badge</sub></sub> Scope duplicate-error suppression to a request

    When a Fastify hook or reply.send() reuses the same Error instance for multiple requests, this process-wide last-error check drops every request after the first. The Fastify plugin's error subscriber delegates to web.addError(req, error) (packages/datadog-plugin-router/src/index.js:70-71), which records the error on the span for that specific req (packages/dd-trace/src/plugins/util/web.js:246-251), so later request spans never get tagged. Please scope the dedupe to the avvio re-drive/request instead of the last error object globally.

    Useful? React with 👍 / 👎.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Jun 28, 2026 00:33 UTC
    Reviewer

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 0d544ad623

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Codex has been enabled to automatically 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 👍.

    When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

    </details>

    crysmags crysmags commented on code on Jul 02, 2026 14:49 UTC
    Code Review
    packages/datadog-instrumentations/src/fastify.js:1
    @@ -305,11 +310,19 @@ function getRouteConfig (request) {
     }
     
     function publishError (ctx) {
    -  if (ctx.error) {
    -    publishErrorChannel(ctx)
    -  }
    -
    -  return ctx.error
    +  const error = ctx.error
    +  if (!error) return
    +
    +  // avvio's boot loop (`_encapsulateThreeParam`) re-invokes the same encapsulated
    +  // hook after it throws, re-throwing the same error object on every re-drive
    +  // (#9099). Each re-drive is sequential, so the channel's in-flight flag has
    +  // already reset; the re-drive carries the one caught error on every hop, so a
    +  // reference compare against the previously published error terminates the loop
    +  // before the subscriber recurses and boot overflows the stack.
    +  if (error === lastPublishedError) return

    this needs a request boundary. lastPublishedError fixes the avvio re-drive, but it also drops a later request if the app reuses the same Error instance.

    The channel subscribers are request-scoped: router calls web.addError(req, error), and RASP blocking uses the current request/response. If request 2 hits the same cached error object, it never reaches either subscriber.

    I reproduced it on this head with two different req objects and one shared Error: publish count was 1, for req 1 only. Add a regression test for same-error / different-request before this lands.

    crysmags crysmags requested changes on Jul 02, 2026 14:49 UTC
    Changes Requested Reviewer

    one blocker, otherwise this looks good.

    lastPublishedError is still keyed only on the Error object. That fixes the avvio re-drive, but it also drops a later request if the app reuses the same Error instance.

    crysmags crysmags approved these changes on Jul 06, 2026 17:56 UTC
    Approved Reviewer

    Approved!

    Reviewers
    Assignees
    BridgeAR BridgeAR
    Labels
    risk: low confidence: 72.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.4% (MEDIUM) · Higher = larger blast radius
    37.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 72.6% · Lower = rushed or shallow review
    72.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 10.3% · Safe to merge
    10.3%