Skip to content

fix(openfeature): keep the process alive while provider initialization is pending - #11393

Open
tlhunter wants to merge 1 commit into
masterfrom
tlhunter/openfeature-init-hold
Open

tlhunter wants to merge 1 commit into
masterfrom
tlhunter/openfeature-init-hold

Conversation

@tlhunter

Copy link
Copy Markdown
Member

What does this PR do?

Fixes #11355. With the flagging provider enabled, an otherwise idle process that awaited OpenFeature.setProviderAndWait(tracer.openfeature) exited with code 0 if the first configuration did not arrive promptly. Initialization was still pending at exit, nothing was thrown or logged, and the initialization timeout never fired.

Every timer that could keep the process alive during initialization is unref'd: the vendored @datadog/openfeature-node-server initialization timer, the agentless retry and poll delays, and the Remote Config poll scheduler. So this affects both configuration sources, not only agentless, for network errors and for HTTP failures such as 500 or 403.

While initialize() waits for configuration, FlaggingProvider now holds a ref'd timer bounded by the initialization timeout (DD_EXPERIMENTAL_FLAGGING_PROVIDER_INITIALIZATION_TIMEOUT_MS, 30s by default). The timer is released when configuration arrives, when initialization fails or times out, and when the provider closes. setProviderAndWait therefore always settles: it resolves when configuration arrives, or rejects with Initialization timeout after <n>ms.

With an unreachable agentless endpoint:

master (default 30s timeout):
exit code=0 after 212 ms

this branch (2000ms timeout):
provider failed after 2026 ms: Initialization timeout after 2000ms
exit code=1 after 2029 ms

Motivation

A server that awaits the provider before it starts listening exits 0 shortly after start when the flag endpoint is unreachable. In Kubernetes this shows up as Completed and then CrashLoopBackOff, with nothing pointing at flag delivery. The documented getting-started pattern, await OpenFeature.setProviderAndWait(...) inside try/catch, is exactly the one that hits it.

Israel Lopez from Datadog Support did the investigation this fix builds on, and it saved a lot of time:

  • Reproduced it across versions. Israel reproduced it with the reported versions and showed it behaves the same on 5.137.0, 6.26.0 and master, for HTTP 500 and 403 as well as network errors. That ruled out a recent regression and a network-error-only path, so the fix belongs in initialization and not in the request or retry logic.
  • Confirmed the cause in the source. The unref'd retry sleep and initialization timeout are what leave the event loop empty. That led directly to checking every timer involved in initialization, which is how the Remote Config source turned out to be affected too.
  • Tested fix(openfeature): fail agentless initialization instead of exiting with code 0 #11357 and found its gaps. The process still exited 0 when the provider was awaited a little after startup, and a longer initialization timeout was not honored. Both became requirements here. The hold is tied to the pending initialization rather than to individual poll delays, so it works no matter when initialization starts and lasts for the configured timeout. Both cases have tests below.
  • Settled bug versus expected behavior. Israel pointed out that the getting-started docs example is exactly the failing pattern, which made clear this is a bug rather than behavior to document.

Additional Notes

  • Trade-off: OpenFeature.setProvider() without await also calls initialize(), and the provider cannot tell whether anyone is waiting. A short script or serverless handler that sets the provider without awaiting it, and whose configuration never arrives, now stays alive until the initialization timeout instead of exiting at once. When configuration arrives nothing changes, and a process that never sets the provider is not held. This reverses the deliberate unref from feat(openfeature): vendor the flagging provider instead of an optional peer dependency #9570, which the replaced test does not keep the process alive while waiting for configuration pinned. The initializationTimeoutMs docs in index.d.ts now mention the hold.
  • The hold is a timer the provider owns. It does not re-ref the upstream initController.timeoutId, which is private upstream.
  • This takes a different approach from fix(openfeature): fail agentless initialization instead of exiting with code 0 #11357. That PR holds only the agentless retry delays and fails initialization once a poll cycle ends. This PR fixes both configuration sources in one place and keeps the configured timeout semantics.
  • Tests:
    • initialization-process.spec.js (new) runs the real tracer in a child process with nothing else keeping it alive. It checks rejection with the timeout for an unreachable agentless endpoint, for an unreachable agent, and when initialization starts after the first poll has already failed. It also checks that a 503 followed by configuration makes initialization succeed after a retry, and that the process then exits. Two guard cases check that a provider that is never initialized, or that is closed during initialization, does not hold the process. The four bug cases fail on master.
    • flagging_provider_timeout.spec.js checks that the hold is released on each path, is replaced by a repeated initialization, and is not taken when configuration arrived first.
  • Validation: npm run test:openfeature (965 passing), npm run test:integration:openfeature (13 passing), and eslint on the changed files. npm run lint:editorconfig was not run locally.

🤖 Generated with Claude Code

…n is pending

The upstream initialization timer and the agentless and Remote Config polling
timers are all unref'd. An otherwise idle process awaiting
`OpenFeature.setProviderAndWait()` therefore exited with code 0 while
initialization was still pending whenever the first configuration did not
arrive promptly, without an error or a timeout rejection.

While `initialize()` waits for configuration, the provider now holds a ref'd
timer bounded by the initialization timeout. It is released when
configuration arrives, initialization fails or times out, or the provider
closes.

Fixes #11355

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tlhunter
tlhunter requested review from a team as code owners November 23, 2026 19:42
@tlhunter
tlhunter requested review from BridgeAR and crysmags and removed request for a team November 23, 2026 19:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T19:43:55.957892Z 1cd6c93 PR opened
🔒 Security Review ✅ Completed 2026-11-23T19:46:56.726603Z 1cd6c93 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.

@dd-octo-sts

dd-octo-sts Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 9.56 MB
Deduped: 10.31 MB
No deduping: 10.31 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.3 | 131.25 kB | 531.9 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

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (6b3f1dc) to head (1cd6c93).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11393      +/-   ##
==========================================
+ Coverage   99.14%   99.15%   +0.01%     
==========================================
  Files        1136     1136              
  Lines      188374   188391      +17     
  Branches       86       86              
==========================================
+ Hits       186766   186807      +41     
+ Misses       1608     1584      -24     
Flag Coverage Δ
ai-guard 63.33% <ø> (-0.02%) ⬇️
apm-capabilities 55.16% <11.76%> (-0.01%) ⬇️
apm-integrations 81.96% <ø> (+0.04%) ⬆️
appsec 59.24% <ø> (-0.01%) ⬇️
debugger 70.89% <ø> (-0.02%) ⬇️
instrumentation 60.17% <ø> (+0.05%) ⬆️
llmobs 82.51% <ø> (-0.02%) ⬇️
master-coverage 99.15% <100.00%> (?)
openfeature 68.08% <100.00%> (-0.01%) ⬇️
platform 68.15% <ø> (-0.01%) ⬇️
profiling 66.51% <ø> (-0.02%) ⬇️
serverless 66.67% <ø> (-0.02%) ⬇️
test-optimization 82.02% <ø> (+0.01%) ⬆️

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.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Tests  Pipelines

⚠️ Warnings

Your PR has warnings. Tests failed — unable to determine if these are from required jobs.

🧪 8 Tests failed in 1 job

APM Integrations | kafkajs — ❌ 8 tests failed

View more details · View in GitHub Actions

❌ Plugin kafkajs with kafkajs >=1.4 (1.16.0) data stream monitoring backlogs "before each" hook for "Should add backlog on consumer explicit commit" from backlogs   View in Datadog
This server does not host this topic-partition

KafkaJSProtocolError: This server does not host this topic-partition
    at createErrorFromCode (versions/kafkajs@1/node_modules/kafkajs/src/protocol/error.js:581:10)
    at Object.parse (versions/kafkajs@1/node_modules/kafkajs/src/protocol/requests/metadata/v0/response.js:56:11)
    at Connection.send (versions/kafkajs@1/node_modules/kafkajs/src/network/connection.js:333:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async [private:Broker:sendRequest] (versions/kafkajs@1/node_modules/kafkajs/src/broker/index.js:947:14)
    at async Broker.metadata (versions/kafkajs@1/node_modules/kafkajs/src/broker/index.js:225:12)
    at async /home/runner/work/dd-trace-js/dd-trace-js/versions/kafkajs@1/node_modules/kafkajs/src/cluster/brokerPool.js:161:25
...
❌ Plugin kafkajs with kafkajs >=1.4 (2.2.4) data stream monitoring backlogs "before each" hook for "Should add backlog on consumer explicit commit" from backlogs   View in Datadog
This server does not host this topic-partition

KafkaJSProtocolError: This server does not host this topic-partition
    at createErrorFromCode (versions/node_modules/kafkajs/src/protocol/error.js:581:10)
    at Object.parse (versions/node_modules/kafkajs/src/protocol/requests/metadata/v0/response.js:55:11)
    at Connection.send (versions/node_modules/kafkajs/src/network/connection.js:433:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async [private:Broker:sendRequest] (versions/node_modules/kafkajs/src/broker/index.js:904:14)
    at async Broker.metadata (versions/node_modules/kafkajs/src/broker/index.js:177:12)
    at async /home/runner/work/dd-trace-js/dd-trace-js/versions/node_modules/kafkajs/src/cluster/brokerPool.js:158:25
...
↳ and 6 more — View all

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 98.58% (+9.00%)

Useful? React with 👍 / 👎

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

@pr-commenter

pr-commenter Bot commented Nov 23, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-23 20:07:19

Comparing candidate commit 1cd6c93 in PR branch tlhunter/openfeature-init-hold with baseline commit 6b3f1dc in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 3 performance regressions! Performance is the same for 2457 metrics, 27 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 ----------------------------------'

scenario:openfeature-initialization-error-24

  • 🟥 cpu_user_time [+166.776ms; +420.283ms] or [+6.124%; +15.433%]
  • 🟥 execution_time [+166.108ms; +417.899ms] or [+5.865%; +14.755%]
  • 🟥 throughput [-53658.876op/s; -21335.257op/s] or [-14.892%; -5.921%]

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

  • unstable max_rss_usage [-62.484MB; +57.669MB] or [-24.116%; +22.258%]

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

  • unstable max_rss_usage [-34.895MB; +37.846MB] or [-9.786%; +10.613%]

scenario:openfeature-initialization-configuration-20

  • unstable cpu_user_time [+205.261ms; +517.997ms] or [+11.459%; +28.918%]
  • unstable execution_time [+206.798ms; +523.553ms] or [+11.508%; +29.135%]
  • unstable instructions [+1.2G instructions; +3.1G instructions] or [+9.023%; +22.657%]
  • unstable max_rss_usage [-3.399MB; +7.857MB] or [-4.444%; +10.271%]
  • unstable throughput [-171358.206op/s; -67924.365op/s] or [-29.307%; -11.617%]

scenario:openfeature-initialization-configuration-24

  • unstable cpu_user_time [+158.746ms; +398.114ms] or [+8.212%; +20.594%]
  • unstable execution_time [+160.388ms; +402.495ms] or [+7.874%; +19.759%]
  • unstable instructions [+1.1G instructions; +2.8G instructions] or [+8.724%; +21.788%]
  • unstable throughput [-101453.896op/s; -40451.118op/s] or [-20.005%; -7.976%]

scenario:openfeature-initialization-configuration-26

  • unstable cpu_user_time [+124.045ms; +415.675ms] or [+6.129%; +20.540%]
  • unstable execution_time [+125.609ms; +416.936ms] or [+6.016%; +19.969%]
  • unstable instructions [+1.2G instructions; +3.0G instructions] or [+8.981%; +22.651%]
  • unstable throughput [-101479.076op/s; -32465.407op/s] or [-20.496%; -6.557%]

scenario:openfeature-initialization-error-20

  • unstable cpu_user_time [+176.366ms; +487.555ms] or [+6.128%; +16.940%]
  • unstable execution_time [+176.471ms; +488.381ms] or [+6.119%; +16.933%]
  • unstable instructions [+1.1G instructions; +3.0G instructions] or [+5.925%; +16.143%]
  • unstable max_rss_usage [-3089.709KB; +4854.800KB] or [-4.119%; +6.471%]
  • unstable throughput [-61795.336op/s; -24346.041op/s] or [-17.402%; -6.856%]

scenario:openfeature-initialization-error-24

  • unstable instructions [+1.2G instructions; +3.0G instructions] or [+6.960%; +17.394%]

scenario:openfeature-initialization-error-26

  • unstable cpu_user_time [+153.107ms; +538.783ms] or [+5.281%; +18.582%]
  • unstable execution_time [+153.824ms; +538.818ms] or [+5.191%; +18.185%]
  • unstable instructions [+1.2G instructions; +3.0G instructions] or [+6.807%; +17.115%]
  • unstable throughput [-60902.578op/s; -19486.568op/s] or [-17.647%; -5.646%]

scenario:openfeature-scale-full-26

  • unstable max_rss_usage [-29.718MB; +36.559MB] or [-13.096%; +16.111%]

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

  • unstable max_rss_usage [-28391.274KB; +27201.559KB] or [-14.594%; +13.982%]

This branch has not been deployed

No deployments
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.

[BUG]: OpenFeature provider: process exits 0 with setProviderAndWait pending when the agentless flag endpoint is unreachable

1 participant