Skip to content

docs: correct context-cancellation claim on non-blocking SetProviderWithContext#515

Open
sueun-dev wants to merge 1 commit into
open-feature:mainfrom
sueun-dev:docs-setprovider-context-cancellation
Open

docs: correct context-cancellation claim on non-blocking SetProviderWithContext#515
sueun-dev wants to merge 1 commit into
open-feature:mainfrom
sueun-dev:docs-setprovider-context-cancellation

Conversation

@sueun-dev

Copy link
Copy Markdown

The godoc on SetProviderWithContext and SetNamedProviderWithContext says:

Returns an error immediately if provider is nil, or if context is cancelled during setup.

The context-cancellation half isn't true. Both call api().SetProvider(ctx, provider), which returns synchronously only when the provider is nil (errNilDefaultProvider/errNilProvider) or is already bound to a different API instance (bindProvider, spec 1.8.4). The context is handed to the background initNew goroutine and never checked synchronously, so a cancelled context with a valid provider returns nil. Only the ...AndWait variants honor cancellation, via the select on ctx.Done() in SetProviderAndWait, and their docs already say so.

The non-blocking behavior looks intended: TestContextAwareInitialization's "async initialization returns immediately" subtest asserts SetProviderWithContext returns immediately without error, and ExampleSetProviderWithContext shows the provider continuing to initialize in the background. So this corrects the comment rather than the code.

With a cancelled context and a valid provider, both functions return nil today:

SetProviderWithContext(cancelledCtx, &NoopProvider{})      // nil
SetNamedProviderWithContext(cancelledCtx, &NoopProvider{}) // nil

I added a subtest under TestContextAwareInitialization covering that, so the contract doesn't silently flip back.

go test --short -tags testtools -race ./openfeature/... passes; gofmt and go vet are clean.

…ithContext

SetProviderWithContext and SetNamedProviderWithContext said they return an
error if the context is cancelled during setup. They don't: both call
api().SetProvider(ctx, provider), which returns synchronously only when the
provider is nil or is already bound to a different API instance. The context
is passed to the background initNew goroutine and never checked synchronously,
so a cancelled context with a valid provider returns nil. Only the ...AndWait
variants honor cancellation, via the select on ctx.Done() in
SetProviderAndWait, and their docs already say so.

The non-blocking behavior is intended: TestContextAwareInitialization's
"async initialization returns immediately" subtest asserts SetProviderWithContext
returns immediately without error, so this corrects the comment rather than the
code. Added a subtest covering the cancelled-context case so the contract does
not silently flip back.

Signed-off-by: Sueun Cho <sueun.dev@gmail.com>
@sueun-dev sueun-dev requested review from a team as code owners June 25, 2026 17:02
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a9fa0930-33a2-4add-bb9f-f9a0837e04f8

📥 Commits

Reviewing files that changed from the base of the PR and between 7d09980 and 2253ac1.

📒 Files selected for processing (2)
  • openfeature/context_aware_test.go
  • openfeature/openfeature.go

📝 Walkthrough

Walkthrough

Doc comments and tests for context-aware provider initialization were updated to reflect that cancelled contexts do not make the async provider setup APIs return errors.

Changes

Context-aware initialization semantics

Layer / File(s) Summary
Docs and cancelled-context test
openfeature/openfeature.go, openfeature/context_aware_test.go
Doc comments for SetProviderWithContext and SetNamedProviderWithContext were revised, and a new subtest asserts both context-aware setters return nil when invoked with an already-cancelled context.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the docs fix for context-cancellation behavior in SetProviderWithContext and its named variant.
Description check ✅ Passed The description matches the changeset and explains the docs correction plus the added test.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.45%. Comparing base (7d09980) to head (2253ac1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #515   +/-   ##
=======================================
  Coverage   86.45%   86.45%           
=======================================
  Files          22       22           
  Lines        2119     2119           
=======================================
  Hits         1832     1832           
  Misses        242      242           
  Partials       45       45           
Flag Coverage Δ
e2e 86.45% <ø> (ø)
unit 86.45% <ø> (ø)

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants