fix: Decouple event processor and data source lifecycles - #531
Merged
Merged
Conversation
beekld
marked this pull request as ready for review
September 21, 2026 22:39
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
tanderson-ld
self-requested a review
September 23, 2026 21:31
tanderson-ld
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
.offlinewith a failure reason. We reuse the existing.offlinemode rather than add a dedicated terminal case, because adding a value to the publicConnectionModeenum 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'sConnectionModehas no error or interrupted value, so.offlineis 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
LDClientoffline. The legacy behavior that calledinternalSetOnline(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).SynchronizingErrorgainshttpStatusCodeandisTerminal; streaming, polling, diagnostics, and events all use the same rule.Flag data source: On a terminal sync error, only
flagSynchronizer.isOnlineis set false,ConnectionInformationrecords failure and setscurrentConnectionModeto.offline, and the client is marked initialized whileLDClient.isOnlinecan stay true. Successful syncs runcheckEstablishingStreaming(..., streamingMode:)to move back from.offlineto streaming or polling. Event reporter: Non-retriable responses drop events and setEventReporter.isOnlinefalse without touching connection information. Event sync completion no longer routes errors throughLDClient.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.