Repository navigation
feat: Apply RETRY to FDv2 synchronizer orchestration - #423
Conversation
…en its payload has a selector
f6af197 to
c2788f3
Compare
…essful connection
…ps the stream open
…the data source has not already failed
…nd remove duplicates
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 843447f. Configure here.
There was a problem hiding this comment.
Risk: medium.
Automated risk review (dry run): Medium
This PR would not be automatically approved. Human approval required.
Why: This reworks FDv2 synchronizer parking, retry, fallback TTL, and the public FDv2SourceResult API in FDv2DataSource, SourceManager, and related synchronizers. Cursor Bugbot also reported an unresolved medium-severity issue in FDv2StreamingSynchronizer where a failed ping poll can be overwritten by the reset-threshold timer.
If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.
Sent by Cursor Approval Agent: Dry-Run PR Approver
| if (!changeSet.getSelector().isEmpty()) { | ||
| sink.setStatus(DataSourceState.VALID, null); | ||
| tryCompleteStart(true, null); | ||
| } |
There was a problem hiding this comment.
Is this change necessarily in scope? Seems like it could be out of scope.
There was a problem hiding this comment.
It is admittedly difficult to draw the line how much to implement at once, and the orchestrator changes necessarily include some FDv1 fallback. If you want me to pull out this block and do it later, I can.
There was a problem hiding this comment.
Good with this change after reading/digging more.
| * @return the delay after jitter, in milliseconds | ||
| */ | ||
| private static long jittered(long delayMillis) { | ||
| return delayMillis - ThreadLocalRandom.current().nextLong(delayMillis / 2 + 1); |
There was a problem hiding this comment.
nit: ThreadLocalRandom isn't common in the code base. Usually an injected Random is used.
There was a problem hiding this comment.
ThreadLocalRandom is used in java-core and okhttp-eventsource. I could inject Random, but we can't use Random.nextLong in Android's version of Java, so it wouldn't be a drop-in replacement exactly. I'm inclined to leave it, unless you feel strongly.
| /** | ||
| * Computes the park delay for a synchronizer. | ||
| * | ||
| * @param parkCount the park count of the synchronizer, including the current failure |
There was a problem hiding this comment.
nit: indicate that parkCount must be 1 or greater.



Summary
Applies the RETRY behavior to FDv2 synchronizer orchestration in the Android SDK, following launchdarkly/java-core#252 and launchdarkly/java-core#253. A synchronizer that fails is parked and retried later, instead of being blocked for good.
Parking
next(), a failure to build, or shutting down on its own. The park delay starts at 5 minutes, doubles with each failure up to 1 hour, and has jitter. After a park, the next synchronizer starts after a failover delay of 0.5-1 seconds.pingevent triggers counts as a success or a failure for the streaming reset threshold.ConnectivityManagernow records an INTERRUPTED status with no error as a failure instead of a successful connection.Directed fallback
Deadlines
System.nanoTime(), so changes to the system clock don't move them.FDv2DataSourceConditionsis removed.Public API
This extends the public
FDv2SourceResultclass incom.launchdarkly.sdk.android.subsystems, the result type that initializers and synchronizers return. It adds two methods:isResetThresholdMet()returns true if the source met its reset threshold at the time of the result. When a synchronizer returns such a result, the data source resets that synchronizer's park count. Results from the existingchangeSet()andstatus()factory methods return false.withResetThresholdMet()returns a copy of the result withisResetThresholdMet()set to true.FDv2SourceResultis part of the early access FDv2 data system. It now carries the same note as the other early access types, saying that it is not stable and not subject to backwards compatibility guarantees or semantic versioning.Not included
FailureClassfrom a newer java-sdk-internal.Retry-After, and reading the TTL from the response. Every directive uses the 1-hour default.Note
Overview
Replaces permanent synchronizer blocking with park-and-retry: failed synchronizers back off (exponential delay with jitter), then become eligible again;
FDv2DataSourceConditionsand its timer-based fallback/recovery races are removed in favor of aMonotonicTime-driven loop that wakes on results, fallback/recovery deadlines, unpark times, and FDv1 fallback TTL.Synchronizers now signal
FDv2SourceResult.isResetThresholdMet()/withResetThresholdMet()(two good polls for FDv1/FDv2 polling, ~60s healthy stream including ping-triggered polls); the orchestrator clears park counts when that fires. Streaming treats unexpected stream-thread death as terminal (rebuild after park). Directed FDv1 fallback uses a default ~1h TTL with jitter, can extend on repeat directives, and can run with no FDv1 synchronizer (INTERRUPTED until TTL). Initializer FDv1 payloads without a selector no longer mark the data source ready.ConnectivityManager keeps the last failure when an INTERRUPTED status arrives with no error. An e2e test stops awaiting
identify().get()when polling never succeeds, relying on cached context instead.Reviewed by Cursor Bugbot for commit a80efe9. Bugbot is set up for automated code reviews on this repo. Configure here.