Skip to content

feat: add option to close streams gracefully at server-side deadline - #2098

Draft
alxckn wants to merge 2 commits into
open-feature:mainfrom
alxckn:feat/stream-deadline-graceful-close
Draft

alxckn wants to merge 2 commits into
open-feature:mainfrom
alxckn:feat/stream-deadline-graceful-close

Conversation

@alxckn

@alxckn alxckn commented Oct 23, 2026

Copy link
Copy Markdown
Member

This PR

Adds an opt-in --stream-deadline-graceful-close flag (FLAGD_STREAM_DEADLINE_GRACEFUL_CLOSE). When enabled, sync (flagd.sync.v1) and event (flagd.evaluation.v1/v2 EventStream) streams that reach the server-side --stream-deadline end with an OK status instead of DEADLINE_EXCEEDED.

Defaults to false, so current behavior is unchanged.

Related Issues

Implements "Option A.2" from #1959: the server ends the stream with OK shortly before the client deadline, so there is no error code unless a stream actually hangs past its normal end.

Why

Every provider recycles its stream every 10 minutes. Because the stream ends with DEADLINE_EXCEEDED, this planned recycle shows up as:

Today each provider has to special-case this. The Python provider demoted the log in open-feature/python-sdk-contrib#405 ("log expected sync-stream recycles at debug, not warning"). A matching change for the Java provider is in progress (open-feature/java-sdk-contrib#1955). Ending the stream with OK on the server fixes this for all providers and for tracing, with no SDK change: every provider already treats a completed stream as a routine reconnect.

Suggested usage

flagd start --stream-deadline 9m --stream-deadline-graceful-close ...

Set the server deadline slightly below the providers' FLAGD_STREAM_DEADLINE_MS (10 min by default). The server then closes healthy streams cleanly, and the client deadline still catches streams that are actually hung.

Notes

  • The sync-stream metric exitReason stays deadline_exceeded in both modes, so dashboards keep the same breakdown.
  • StreamDeadlineGraceful is added next to StreamDeadline in core/pkg/service.Configuration, mirroring how the deadline itself is plumbed.

How to test

make workspace-init
cd flagd && go test ./pkg/service/... ./pkg/runtime/...

TestSyncServiceDeadlineEndToEnd gains a "with graceful deadline" case asserting the stream ends with io.EOF (status OK) rather than DEADLINE_EXCEEDED.

🤖 Generated with Claude Code

Add --stream-deadline-graceful-close (FLAGD_STREAM_DEADLINE_GRACEFUL_CLOSE).
When enabled, sync and event streams reaching the server-side deadline
(--stream-deadline) end with an OK status instead of DEADLINE_EXCEEDED.
Providers already treat a completed stream as a routine reconnect, so
the periodic stream recycle no longer surfaces as an error in provider
logs or gRPC client spans.

Defaults to false, preserving current behavior.

Refs: open-feature#1959

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@netlify

netlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit 0980f73
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/6adb756f94017059c18ef07c

Extract the server-side deadline result of the v1 and v2 event streams
into deadlineExceededResult, removing the duplicated block, and cover
both the graceful and non-graceful paths with a unit test.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant