Repository navigation
Conversation
…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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Overall package sizeSelf size: 9.56 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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
BenchmarksBenchmark execution time: 2026-11-23 20:07:19 Comparing candidate commit 1cd6c93 in PR branch Found 0 performance improvements and 3 performance regressions! Performance is the same for 2457 metrics, 27 unstable metrics.
|
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-serverinitialization 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,FlaggingProvidernow 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.setProviderAndWaittherefore always settles: it resolves when configuration arrives, or rejects withInitialization timeout after <n>ms.With an unreachable agentless endpoint:
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
Completedand thenCrashLoopBackOff, with nothing pointing at flag delivery. The documented getting-started pattern,await OpenFeature.setProviderAndWait(...)insidetry/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:
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.Additional Notes
OpenFeature.setProvider()withoutawaitalso callsinitialize(), 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 testdoes not keep the process alive while waiting for configurationpinned. TheinitializationTimeoutMsdocs inindex.d.tsnow mention the hold.initController.timeoutId, which is private upstream.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 onmaster.flagging_provider_timeout.spec.jschecks that the hold is released on each path, is replaced by a repeated initialization, and is not taken when configuration arrived first.npm run test:openfeature(965 passing),npm run test:integration:openfeature(13 passing), and eslint on the changed files.npm run lint:editorconfigwas not run locally.🤖 Generated with Claude Code