Skip to content

fix: Decouple event processor and data source lifecycles - #531

Merged
beekld merged 4 commits into
v11from
bklimt/SDK-3153/decouple-datasource-events
Sep 23, 2026
Merged

beekld merged 4 commits into
v11from
bklimt/SDK-3153/decouple-datasource-events

Conversation

@beekld

@beekld beekld commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The SDK's flag data source, event processor, and diagnostic reporter shared a single lifecycle. A terminal HTTP error (a 401) from either the event processor or the flag data source took the whole client offline and overwrote the flag-delivery connection state, regardless of which component actually failed. Terminal non-401 handling was also inconsistent. A streaming 403/404 stopped the stream silently while the client still reported online, and polling retried forever.

Each network component now owns its own error handling. A terminal error scopes to the component that hit it. A data-source error stops only flag delivery, an event-processor error stops only event delivery, and neither affects the other. Event-delivery failures no longer modify ConnectionInformation, and a permanently stopped data source is now observable rather than silently stopping while the client reports online.

This also drops the legacy whole-client shutdown on 401, matching the other LaunchDarkly client SDKs.

Note for reviewers

Previously a terminal data-source error had no consistent observable state. A rejected stream could stop while the client still reported online. Now any terminal data-source error sets the connection mode to .offline with a failure reason. We reuse the existing .offline mode rather than add a dedicated terminal case, because adding a value to the public ConnectionMode enum would be a breaking change for consumers that switch over it exhaustively. The FDv2 spec discourages conflating an auth error with a deliberate offline, but FDv1's ConnectionMode has no error or interrupted value, so .offline is the only signal available.


Note

Overview
Decouples flag delivery, event reporting, and diagnostics so a terminal HTTP failure in one path no longer forces the whole LDClient offline. The legacy behavior that called internalSetOnline(false) on flag-sync errors (including 401) is removed.

Terminal 4xx handling is centralized via HTTPURLResponse.StatusCodes.isTerminalStatusCode (retries still allowed for 400, 408, 429). SynchronizingError gains httpStatusCode and isTerminal; streaming, polling, diagnostics, and events all use the same rule.

Flag data source: On a terminal sync error, only flagSynchronizer.isOnline is set false, ConnectionInformation records failure and sets currentConnectionMode to .offline, and the client is marked initialized while LDClient.isOnline can stay true. Successful syncs run checkEstablishingStreaming(..., streamingMode:) to move back from .offline to streaming or polling. Event reporter: Non-retriable responses drop events and set EventReporter.isOnline false without touching connection information. Event sync completion no longer routes errors through LDClient.process.

Polling edge cases: While the synchronizer is offline, in-flight poll responses are ignored and the flag etag cache is cleared so the next poll refetches; cached “up to date” shortcuts are skipped when offline.

Reviewed by Cursor Bugbot for commit 6e72564. Bugbot is set up for automated code reviews on this repo. Configure here.

@beekld
beekld marked this pull request as ready for review September 21, 2026 22:39
@beekld
beekld requested a review from a team as a code owner September 21, 2026 22:39

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

Stale Bugbot comment from a previous run.

Comment thread LaunchDarkly/LaunchDarkly/LDClient.swift

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

Stale Bugbot comment from a previous run.

Comment thread LaunchDarkly/LaunchDarkly/Models/ConnectionInformation.swift

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 051468e. Configure here.

Comment thread LaunchDarkly/LaunchDarkly/ServiceObjects/FlagSynchronizer.swift
Comment thread LaunchDarkly/LaunchDarkly/LDClient.swift
Comment thread LaunchDarkly/LaunchDarkly/ServiceObjects/FlagSynchronizer.swift
Comment thread LaunchDarkly/LaunchDarkly/Models/ConnectionInformation.swift
@tanderson-ld
tanderson-ld self-requested a review September 23, 2026 21:31
@beekld
beekld merged commit 9b5183d into v11 Sep 23, 2026
18 checks passed
@beekld
beekld deleted the bklimt/SDK-3153/decouple-datasource-events branch September 23, 2026 22:32
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