Skip to content

fix(next): trace compiled response lifecycles - #9708

Open
BridgeAR wants to merge 2 commits into
masterfrom
BridgeAR/2026-08-05-fix-next-compiled-cache
Open

fix(next): trace compiled response lifecycles#9708
BridgeAR wants to merge 2 commits into
masterfrom
BridgeAR/2026-08-05-fix-next-compiled-cache

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

Compiled App Route and App Page request spans started inside response generators, so cache hits had no span, stale background revalidations created request spans, and App Route hooks received a synthetic response. Starting at the shared RouteModule response boundary covers the foreground request once and passes the Node response through unchanged.

Refs: #9627
Refs: #9682

@dd-octo-sts

dd-octo-sts Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 7.88 MB
Deduped: 8.54 MB
No deduping: 8.54 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.3 | 125.43 kB | 441.68 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

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

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 5, 2026

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

🚦 3 Pipeline jobs failed

Platform | integration-guardrails (20.0.0)   View in Datadog   GitHub Actions

🔧 Fix in code. This looks caused by changes in this PR. 1 failed test. AssertionError: output does not contain expected output 'true' at runAndCheckOutput (integration-tests/helpers/index.js:72:12)

All Green | all-green   View in Datadog   GitHub Actions

See error xcrun is not installed or can't be found; No gcov data found; coverage.py is not installed or can't be found.

System Tests | main / End-to-end #10 / nextjs 10   View in Datadog   GitHub Actions

📋 Copy prompt for your agent
CI on my pull request is failing. Help me find and fix the root cause of each failing job below — they were flagged as caused by changes in this PR, so focus on the diff. For each job, explain the failure and propose a fix.

Branch: BridgeAR/2026-08-05-fix-next-compiled-cache

Platform | integration-guardrails (20.0.0)
Commit: d0f8e044ef771b9ba35c3da09bb38eeac009b946
Error (code / test):
1 failed test. AssertionError: output does not contain expected output 'true' at runAndCheckOutput (integration-tests/helpers/index.js:72:12)
CI job: https://github.com/DataDog/dd-trace-js/actions/runs/31058304276/job/92481115063

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.48% (-0.05%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7a3d98f | Docs | Datadog PR Page | Give us feedback!

@BridgeAR
BridgeAR marked this pull request as ready for review August 5, 2026 22:47
@BridgeAR
BridgeAR requested a review from a team as a code owner August 5, 2026 22:47
@BridgeAR
BridgeAR requested review from wconti27 and removed request for a team August 5, 2026 22:47
@pr-commenter

pr-commenter Bot commented Aug 5, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-06 00:09:53

Comparing candidate commit 7a3d98f in PR branch BridgeAR/2026-08-05-fix-next-compiled-cache with baseline commit 09884bf in branch master.

📊 Benchmarking dashboard

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

Explanation

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.

More details about the CI and significant changes

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 ----------------------------------'

Unstable benchmarks

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 [-210.120ms; +195.310ms] or [-7.788%; +7.239%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-238.308ms; +220.146ms] or [-9.212%; +8.510%]

scenario:appsec-appsec-enabled-with-attacks-24

  • unstable execution_time [-168.652ms; +156.651ms] or [-5.420%; +5.034%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-191.846ms; +180.261ms] or [-6.566%; +6.170%]

scenario:appsec-control-20

  • unstable execution_time [-116.832ms; +143.361ms] or [-7.005%; +8.596%]

scenario:appsec-control-24

  • unstable execution_time [-106.046ms; +120.865ms] or [-8.513%; +9.703%]

scenario:appsec-control-26

  • unstable execution_time [-125660.594µs; +126682.827µs] or [-10.078%; +10.160%]

scenario:appsec-iast-no-vulnerability-control-20

  • unstable execution_time [-14363.828µs; +12841.761µs] or [-5.508%; +4.924%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-12.671ms; +18.006ms] or [-4.890%; +6.949%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-14745.596µs; +16313.882µs] or [-5.663%; +6.266%]

scenario:appsec-iast-with-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-30.571ms; +26.783ms] or [-5.418%; +4.746%]

scenario:child_process-shell-string-24

  • unstable execution_time [-18.882ms; +16.354ms] or [-5.848%; +5.065%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-2412.621ms; +2885.984ms] or [-26.977%; +32.270%]
  • unstable execution_time [-2488.345ms; +2957.330ms] or [-25.772%; +30.629%]
  • unstable instructions [-20.2G instructions; +24.5G instructions] or [-27.628%; +33.463%]
  • unstable max_rss_usage [-9346.941KB; +10636.541KB] or [-5.786%; +6.584%]
  • unstable throughput [-833.124op/s; +644.525op/s] or [-23.917%; +18.503%]

scenario:debugger-line-probe-with-snapshot-default-26

  • unstable cpu_user_time [-2320.625ms; +752.089ms] or [-24.299%; +7.875%]
  • unstable execution_time [-2339.398ms; +759.166ms] or [-22.753%; +7.384%]
  • unstable instructions [-20.6G instructions; +6.8G instructions] or [-25.876%; +8.491%]
  • unstable throughput [-151.205op/s; +457.707op/s] or [-4.685%; +14.183%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable cpu_user_time [-2014.799ms; +2857.613ms] or [-24.282%; +34.439%]
  • unstable execution_time [-2194.650ms; +3092.214ms] or [-24.320%; +34.266%]
  • unstable instructions [-16.9G instructions; +24.2G instructions] or [-25.100%; +35.831%]
  • unstable max_rss_usage [-7920.856KB; +9756.056KB] or [-4.979%; +6.133%]
  • unstable throughput [-836.516op/s; +627.337op/s] or [-22.824%; +17.116%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-2.071s; +4.392s] or [-23.285%; +49.387%]
  • unstable execution_time [-2.179s; +4.574s] or [-22.647%; +47.534%]
  • unstable instructions [-17.3G instructions; +37.5G instructions] or [-23.845%; +51.546%]
  • unstable max_rss_usage [-9.098MB; +18.612MB] or [-5.699%; +11.659%]
  • unstable throughput [-1198.418op/s; +580.767op/s] or [-34.238%; +16.592%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-3738.405ms; +3748.009ms] or [-36.242%; +36.335%]
  • unstable execution_time [-3909.255ms; +3917.476ms] or [-35.376%; +35.450%]
  • unstable instructions [-32895.1M instructions; +32887.6M instructions] or [-38.037%; +38.028%]
  • unstable max_rss_usage [-12526.496KB; +12702.496KB] or [-7.801%; +7.910%]
  • unstable throughput [-744.470op/s; +765.209op/s] or [-24.099%; +24.770%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-238.840ms; +464.552ms] or [-5.030%; +9.783%]
  • unstable execution_time [-238.511ms; +463.858ms] or [-4.946%; +9.619%]
  • unstable throughput [-164837.041op/s; +87099.680op/s] or [-9.465%; +5.001%]

scenario:plugin-claude-agent-sdk-compact-stream-scan-26

  • unstable cpu_usage_percentage [-4.453%; +5.628%]

scenario:plugin-graphql-long-with-depth-and-collapse-off-20

  • unstable max_rss_usage [-14.814MB; +34.551MB] or [-3.778%; +8.810%]

scenario:plugin-graphql-long-with-depth-off-20

  • unstable max_rss_usage [-6770.003KB; +8249.432KB] or [-5.227%; +6.369%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [-20.280MB; +40.403MB] or [-10.187%; +20.295%]

scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable cpu_user_time [-601.778ms; +558.635ms] or [-5.216%; +4.842%]
  • unstable execution_time [-614.385ms; +572.983ms] or [-5.217%; +4.866%]
  • unstable throughput [-3.359op/s; +3.621op/s] or [-4.917%; +5.301%]

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

ℹ️ About Codex in GitHub

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

Comment thread packages/datadog-instrumentations/src/next.js
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (09884bf) to head (7a3d98f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9708      +/-   ##
==========================================
+ Coverage   97.93%   98.47%   +0.54%     
==========================================
  Files         964      964              
  Lines      136442   136610     +168     
  Branches    11952    11774     -178     
==========================================
+ Hits       133619   134531     +912     
+ Misses       2823     2079     -744     
Flag Coverage Δ
aiguard 57.04% <ø> (-0.02%) ⬇️
aiguard-integration 55.94% <ø> (-0.01%) ⬇️
apm-bucket-0 57.28% <ø> (-0.02%) ⬇️
apm-bucket-1 63.48% <ø> (-0.03%) ⬇️
apm-bucket-2 62.31% <ø> (-0.03%) ⬇️
apm-bucket-3 59.87% <ø> (-0.03%) ⬇️
apm-capabilities-tracing 62.74% <44.58%> (-0.01%) ⬇️
apm-integrations-aerospike 56.34% <ø> (-0.02%) ⬇️
apm-integrations-confluentinc-kafka-javascript 61.29% <ø> (+0.01%) ⬆️
apm-integrations-couchbase 56.76% <ø> (-0.02%) ⬇️
apm-integrations-http 62.29% <ø> (-0.03%) ⬇️
apm-integrations-kafkajs 61.82% <ø> (-0.02%) ⬇️
apm-integrations-next 59.83% <100.00%> (+0.33%) ⬆️
apm-integrations-prisma 58.41% <ø> (-0.02%) ⬇️
appsec 72.08% <ø> (?)
appsec-express_fastify_graphql 69.53% <ø> (-0.02%) ⬇️
appsec-integration 50.32% <46.35%> (+0.01%) ⬆️
appsec-kafka_ldapjs_lodash 63.51% <ø> (-0.02%) ⬇️
appsec-mongodb-core_mongoose_mysql 67.08% <ø> (-0.02%) ⬇️
appsec-next 56.92% <59.74%> (+0.02%) ⬆️
appsec-node-serialize_passport_postgres 66.73% <ø> (-0.02%) ⬇️
appsec-sourcing_stripe_template 65.12% <ø> (-0.02%) ⬇️
debugger 64.35% <ø> (-0.03%) ⬇️
instrumentations-bucket-0 51.70% <ø> (-0.02%) ⬇️
instrumentations-bucket-1 59.50% <ø> (-0.03%) ⬇️
instrumentations-bucket-10 61.39% <ø> (-0.03%) ⬇️
instrumentations-bucket-11 56.44% <ø> (-0.02%) ⬇️
instrumentations-bucket-12 52.16% <ø> (-0.02%) ⬇️
instrumentations-bucket-13 52.04% <ø> (-0.02%) ⬇️
instrumentations-bucket-2 53.19% <ø> (-0.02%) ⬇️
instrumentations-bucket-3 53.52% <ø> (-0.02%) ⬇️
instrumentations-bucket-4 58.84% <ø> (-0.03%) ⬇️
instrumentations-bucket-5 50.16% <ø> (-0.02%) ⬇️
instrumentations-bucket-6 60.59% <ø> (-0.03%) ⬇️
instrumentations-bucket-7 58.16% <ø> (-0.03%) ⬇️
instrumentations-bucket-8 59.08% <ø> (-0.02%) ⬇️
instrumentations-bucket-9 51.94% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-couchbase 50.98% <ø> (-0.03%) ⬇️
instrumentations-instrumentation-zlib 51.61% <ø> (-0.02%) ⬇️
instrumentations-integration-esbuild 34.23% <46.35%> (+0.05%) ⬆️
llmobs-ai_anthropic_bedrock 62.91% <ø> (-0.02%) ⬇️
llmobs-bucket-1 61.39% <ø> (-0.02%) ⬇️
llmobs-openai 61.88% <ø> (-0.02%) ⬇️
llmobs-openai-agents_vertex-ai 59.88% <ø> (-0.02%) ⬇️
llmobs-sdk 66.67% <ø> (-0.02%) ⬇️
master-coverage 98.47% <100.00%> (?)
openfeature 55.75% <ø> (-0.01%) ⬇️
openfeature-unit 53.25% <ø> (-0.02%) ⬇️
platform-core_esbuild_instrumentations-misc 40.75% <46.35%> (+0.02%) ⬆️
platform-integration 60.57% <ø> (-0.01%) ⬇️
platform-shimmer_unit-guardrails_webpack 38.98% <46.35%> (+0.02%) ⬆️
plugins-bucket-0 56.97% <ø> (-0.02%) ⬇️
plugins-bucket-1 54.08% <ø> (-0.01%) ⬇️
plugins-bucket-11 61.56% <ø> (-0.45%) ⬇️
plugins-bucket-14 58.88% <ø> (?)
plugins-bucket-17 61.41% <ø> (?)
plugins-bucket-18 58.16% <ø> (-3.44%) ⬇️
plugins-bucket-19 61.48% <ø> (+1.65%) ⬆️
plugins-bucket-20 61.82% <ø> (+0.04%) ⬆️
plugins-bucket-4 58.40% <ø> (-0.03%) ⬇️
plugins-bullmq_cassandra_cookie 61.47% <ø> (-0.02%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 56.40% <ø> (-0.02%) ⬇️
plugins-fetch_fs_generic-pool 58.31% <ø> (-0.02%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 64.26% <ø> (-0.03%) ⬇️
plugins-hapi_hono_ioredis 59.98% <ø> (-0.03%) ⬇️
plugins-jest_knex_langgraph ?
plugins-jest_langgraph_ldapjs 55.37% <ø> (?)
plugins-ldapjs_light-my-request_limitd-client ?
plugins-light-my-request_limitd-client_lodash 58.44% <ø> (?)
plugins-lodash_mariadb_memcached ?
plugins-mariadb_memcached_mercurius 61.40% <ø> (?)
plugins-moleculer_mongodb_mongodb-core ?
plugins-mongodb-core_mongoose_multer 58.99% <ø> (?)
plugins-mongoose_multer_mysql ?
plugins-mysql2_nats_node-serialize ?
plugins-mysql_mysql2_nats 60.53% <ø> (?)
plugins-opensearch_passport-http_pino ?
plugins-pino_postgres_process 58.67% <ø> (?)
plugins-postgres_process_pug ?
plugins-pug_redis_router 61.66% <ø> (?)
plugins-redis_router_sequelize ?
plugins-test-and-upstream-rhea_undici_url ?
plugins-url_valkey_vm 57.14% <ø> (?)
plugins-valkey_vm_winston ?
plugins-winston_ws 59.67% <ø> (?)
plugins-ws ?
profiling 61.63% <ø> (-0.03%) ⬇️
serverless-aws-sdk-aws-sdk 55.01% <ø> (-0.02%) ⬇️
serverless-aws-sdk-base-inject-field 50.93% <ø> (-0.03%) ⬇️
serverless-aws-sdk-bedrockruntime 54.68% <ø> (-0.02%) ⬇️
serverless-aws-sdk-client 56.26% <ø> (-0.02%) ⬇️
serverless-aws-sdk-dynamodb 55.54% <ø> (-0.01%) ⬇️
serverless-aws-sdk-eventbridge 49.58% <ø> (-0.02%) ⬇️
serverless-aws-sdk-kinesis 59.15% <ø> (-0.02%) ⬇️
serverless-aws-sdk-lambda 57.28% <ø> (-0.02%) ⬇️
serverless-aws-sdk-s3 55.62% <ø> (-0.02%) ⬇️
serverless-aws-sdk-serverless-peer-service 59.41% <ø> (-0.02%) ⬇️
serverless-aws-sdk-sns 59.96% <ø> (-0.02%) ⬇️
serverless-aws-sdk-sqs 60.42% <ø> (+0.02%) ⬆️
serverless-aws-sdk-stepfunctions 55.45% <ø> (-0.02%) ⬇️
serverless-aws-sdk-util 51.46% <ø> (-0.03%) ⬇️
serverless-bucket-0 54.15% <ø> (-0.01%) ⬇️
serverless-bucket-1 58.92% <ø> (-0.02%) ⬇️
test-optimization-cucumber 71.55% <ø> (-0.01%) ⬇️
test-optimization-cypress 65.21% <ø> (+<0.01%) ⬆️
test-optimization-jest 73.02% <ø> (-0.01%) ⬇️
test-optimization-mocha 72.60% <ø> (+0.04%) ⬆️
test-optimization-playwright-playwright-atr 60.23% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-efd 60.37% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-final-status 60.53% <ø> (-0.02%) ⬇️
test-optimization-playwright-playwright-impacted-tests 60.06% <ø> (+0.13%) ⬆️
test-optimization-playwright-playwright-reporting 61.24% <ø> (-0.12%) ⬇️
test-optimization-playwright-playwright-test-management 60.74% <ø> (-0.43%) ⬇️
test-optimization-playwright-playwright-test-span 60.28% <ø> (-0.08%) ⬇️
test-optimization-selenium 59.47% <ø> (-0.16%) ⬇️
test-optimization-testopt 57.98% <ø> (+0.07%) ⬆️
test-optimization-vitest 73.61% <ø> (+0.02%) ⬆️
test-optimization-vitest-browser 59.06% <ø> (-0.02%) ⬇️
test-optimization-webdriverio 64.48% <ø> (-0.39%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/datadog-instrumentations/src/next.js Outdated
Compiled App Route and App Page request spans started inside response generators, so cache hits had no span, stale background revalidations created request spans, and App Route hooks received a synthetic response. Starting at the shared RouteModule response boundary covers the foreground request once and passes the Node response through unchanged.
## Summary

- Finish compiled App Page spans after cache handling and the Node response lifecycle.
- Clear App Route request associations when response generators throw synchronously.

## Why

Next can rewrite cached App Page statuses and report errors after handleResponse() resolves. A synchronous generator throw could also retain a stale request association and attach errors from fallback handling to the wrong span.

## Test plan

- Run the compiled runtime plugin tests.
- Run Next 15.4.1 App Page rendering and error tests.
- Run changed-line coverage and the full lint suite.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-08-05-fix-next-compiled-cache branch from e0e7655 to 7a3d98f Compare August 6, 2026 00:01

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

ℹ️ About Codex in GitHub

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

/** @param {NextErrorContext} ctx */
error ({ span, error, req }) {
if (!span && req) {
span = this.#deferredRequestContexts.get(req)?.currentStore?.span

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid tagging stale revalidations on cached responses

When an ISR App Page serves a stale cache entry, Next resolves the cached response first and keeps the responseGenerator running in the background; if that background render reports onRequestError before the Node response emits finish/close, the error message uses the same req, so this deferred lookup retrieves the foreground cached response context and marks that user-facing span as failed. That makes successful stale-cache hits look like errored requests even though only revalidation failed, so the deferred lookup needs to distinguish foreground errors from background revalidation errors.

Useful? React with 👍 / 👎.

ctx.responseFinished = true
if (!ctx.handlerFinished) return

this.#finishDeferred(ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard deferred App Page finish hooks

For compiled App Page requests where handleResponse resolves before the Node response emits finish/close, any exception from the configured hooks.request now escapes this response listener because #finishDeferred calls #finish directly instead of through the diagnostic-channel subscriber wrapper that normally catches plugin errors. A throwing hook is user code and should only disable/log the plugin; here it can throw out of ServerResponse.emit('finish') and crash the app.

Useful? React with 👍 / 👎.

Comment on lines +1187 to +1209
it('clears the App Route request association after a synchronous generator error', async () => {
const nextRequest = {
error: new Error('unrelated Next request error'),
headers: {},
method: 'GET',
url: '/api/generator-error',
}

class AppRouteRouteModule extends RouteModule {
definition = { pathname: '/api/generator-error' }

handle () {
return Promise.resolve({ status: 200 })
}

/** @param {{responseGenerator: () => Promise<unknown>}} options */
async handleResponse ({ responseGenerator }) {
assert.throws(responseGenerator, /synchronous generator error/)
const response = await this.handle(nextRequest, {})
return { value: { status: response.status } }
}
}
getCompiledRuntimeHook('app-route')({ AppRouteRouteModule })

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.

Not a required change, but it wouldnt hurt to have an actual compiled next test app, and verifying the caching behavior that way instead of via manually constructed fixtures

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

Both codex comments also look legitimate as well

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants