Skip to content

feat: Apply RETRY to FDv2 synchronizer orchestration - #252

Merged
beekld merged 21 commits into
mainfrom
bklimt/SDK-3402/retry-parking
Nov 12, 2026
Merged

beekld merged 21 commits into
mainfrom
bklimt/SDK-3402/retry-parking

Conversation

@beekld

@beekld beekld commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Applies the RETRY behavior to FDv2 synchronizer orchestration in the server SDK. A synchronizer that fails is parked and retried later, instead of being blocked for good.

Parking

  • A synchronizer that fails unexpectedly is parked: a terminal error, an exception from 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.
  • A synchronizer's park count resets when it meets its reset threshold. For polling, that's two successful polls in a row. For streaming, it's staying connected for 60 seconds.
  • When every synchronizer is parked, the data system waits for the earliest unpark time. Synchronization stops only when the data source is closed.
  • When the fallback condition is met but no other synchronizer is available, the current synchronizer keeps running.

Directed fallback

  • The fallback to FDv1 now ends after a TTL, which defaults to 1 hour with jitter. The data system then restarts the FDv2 synchronizers.
  • A directive received during the fallback extends the TTL.
  • A directive with no FDv1 fallback synchronizer configured no longer halts the data system. It reports INTERRUPTED and restarts the FDv2 synchronizers when the TTL ends.

Conditions removed

  • The Conditions class and FDv2DataSourceConditions are removed. They weren't compatible with the new parking and FDv1 fallback timers, so the synchronizer loop is simplified to check all of its timers each time it wakes.

Not included

  • Honoring Retry-After.
  • Reading the TTL from the response. Every directive uses the 1-hour default.

Note

Overview
Replaces the old condition/timer model (FDv2DataSourceConditions, FDv2DataSource.Conditions) with a single synchronizer loop that wakes on results or deadlines (fallback, recovery, unpark, FDv1 TTL). Failed synchronizers are parked with exponential backoff (5 min → 1 h, jitter) instead of being blocked for the process lifetime; terminal errors and build failures park the source rather than permanently blocking it.

Adds AsyncLatch so close() and timed waits can race CompletableFuture.anyOf without leaking completion nodes on long-lived streams.

FDv1 fallback is time-bounded (default 1 h, jitter): SourceManager tracks end time, blocks FDv2 sources during fallback, and returns when TTL expires. Server directives extend TTL or switch to FDv1 without halting the whole data system when no FDv1 synchronizer exists (reports INTERRUPTED and waits for TTL).

Reset threshold is propagated via FDv2SourceResult.resetThresholdMet — polling (2 successes), streaming (60 s healthy), FDv1 adapter (2 VALID) — and resets park counts. HTTP/transport classification (FailureClass) turns unexpected errors into terminal results in polling, streaming, and the FDv1 synchronizer adapter.

close() releases the latch, shuts down sources, and joins the run thread (5 s cap) before reporting OFF.

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

@beekld
beekld force-pushed the bklimt/SDK-3402/retry-parking branch from 0cf207f to 8aa8c77 Compare November 6, 2026 00:49
@beekld
beekld marked this pull request as ready for review November 6, 2026 00:54
@beekld
beekld requested a review from a team as a code owner November 6, 2026 00:55
@beekld
beekld added this pull request to stack #254 November 6, 2026 03:27
@beekld
beekld force-pushed the bklimt/SDK-3402/retry-parking branch from f78d65f to 0dafa42 Compare November 6, 2026 17:37

@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 0dafa42. Configure here.

@beekld
beekld force-pushed the bklimt/SDK-3402/retry-parking branch from 0dafa42 to a700bff Compare November 10, 2026 21:42
@beekld
beekld requested a review from tanderson-ld November 11, 2026 01:53
@beekld
beekld merged commit 6a4aac5 into main Nov 12, 2026
30 checks passed
@beekld
beekld deleted the bklimt/SDK-3402/retry-parking branch November 12, 2026 18:42
beekld added a commit that referenced this pull request Nov 12, 2026
## Summary

The FDv2 synchronizer loop measured its deadlines against the wall
clock. When the system clock stepped backwards, every pending deadline
was delayed by the size of the step. If every synchronizer was parked
for 5 minutes and the clock stepped back an hour, no synchronizer ran
for 65 minutes.

These deadlines now use `MonotonicTime`, a small value class over
`System.nanoTime()`, so changes to the system clock don't move them.

Stacked on #252.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> FDv2 synchronizer orchestration previously scheduled **recovery**,
**fallback**, **park/unpark**, and **FDv1 fallback TTL** deadlines using
wall-clock `Instant`. A backward system clock step could postpone those
deadlines and keep sources parked or on FDv1 longer than intended.
> 
> This PR introduces **`MonotonicTime`** (backed by `System.nanoTime()`)
and wires it through `FDv2DataSource`, `SourceManager`, and
`SynchronizerFactoryWithState` for all internal wait/deadline logic
(`awaitUntil`, `earliest`, parking, fallback end times).
**`MonotonicTimeTest`** covers comparison and duration math across
nanosecond counter overflow.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d8cd1e1. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
beekld pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[7.18.0](launchdarkly-java-server-sdk-7.17.5...launchdarkly-java-server-sdk-7.18.0)
(2026-11-12)


### Features

* Apply RETRY to FDv2 synchronizer orchestration
([#252](#252))
([6a4aac5](6a4aac5))


### Bug Fixes

* Include the big segments status on evaluation reasons when a flag
fails to evaluate
([#258](#258))
([ce08ae8](ce08ae8))
* Make TestData valueForAll return its value when targeting is off
([#251](#251))
([db17ab9](db17ab9))
* Measure synchronizer deadlines with a monotonic clock
([#253](#253))
([3c7da2c](3c7da2c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> This **Release Please** PR cuts **launchdarkly-java-server-sdk
7.18.0** by bumping version metadata only:
`.release-please-manifest.json`, `lib/sdk/server/gradle.properties`, and
`Version.SDK_VERSION` move from **7.17.5** to **7.18.0**.
> 
> `CHANGELOG.md` gains a **7.18.0** section that records what ships in
this artifact (already merged elsewhere): **RETRY** on FDv2 synchronizer
orchestration; big-segments status on evaluation reasons when evaluation
fails; `TestData` `valueForAll` honoring its value when targeting is
off; synchronizer deadlines measured with a monotonic clock. This diff
does not contain those implementation changes.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
aa18674. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
beekld added a commit to launchdarkly/android-client-sdk that referenced this pull request Nov 30, 2026
## 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**
- A synchronizer that fails unexpectedly is parked. That covers a
terminal error, a failed or throwing `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.
- A synchronizer's park count resets when it meets its reset threshold.
For the FDv2 polling and FDv1 fallback synchronizers, that's two
successful polls in a row. For streaming, it's staying connected for 60
seconds.
- The poll that a `ping` event triggers counts as a success or a failure
for the streaming reset threshold.
- When every synchronizer is parked, the data source reports INTERRUPTED
and waits for the earliest unpark time. Synchronization stops only when
the data source is stopped.
- Fallback and recovery switch only to a synchronizer that isn't parked.
When the fallback condition is met but no other synchronizer is
available, the current synchronizer keeps running.
- An exception on the stream thread is now terminal, so the streaming
synchronizer is parked and rebuilt instead of staying dead.
- The FDv2 status sink in `ConnectivityManager` now records an
INTERRUPTED status with no error as a failure instead of a successful
connection.

**Directed fallback**
- The fallback to FDv1 now ends after a TTL, which defaults to 1 hour
with jitter. The data source then restarts the FDv2 synchronizers.
- A directive received during the fallback extends the TTL.
- A directive with no FDv1 fallback synchronizer configured is no longer
ignored. The data source reports INTERRUPTED, runs no synchronizer, and
restarts the FDv2 synchronizers when the TTL ends.
- When an initializer's directive comes with a payload that has no
selector, the payload is applied but no longer marks the data source
ready. Readiness waits for the next source's data, as the data system
spec requires.

**Deadlines**
- The synchronizer loop checks its fallback, recovery, unpark, and TTL
deadlines each time it wakes. The deadlines use `System.nanoTime()`, so
changes to the system clock don't move them. `FDv2DataSourceConditions`
is removed.

**Public API**

This extends the public `FDv2SourceResult` class in
`com.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 existing `changeSet()` and `status()` factory methods return
false.
- `withResetThresholdMet()` returns a copy of the result with
`isResetThresholdMet()` set to true.

`FDv2SourceResult` is 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**
- Treating TLS certificate failures as terminal. That needs
`FailureClass` from a newer java-sdk-internal.
- Honoring `Retry-After`, and reading the TTL from the response. Every
directive uses the 1-hour default.



<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Replaces permanent synchronizer blocking with **park-and-retry**:
failed synchronizers back off (exponential delay with jitter), then
become eligible again; **`FDv2DataSourceConditions`** and its
timer-based fallback/recovery races are removed in favor of a
**`MonotonicTime`**-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.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a80efe9. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
tanderson-ld added a commit that referenced this pull request Dec 1, 2026
…tracker (#293)

Fixes #292
Tracks SDK-3795

## Problem

With the FDv2 data system, `FDv2DataSource` reports `INTERRUPTED` with
no error while every synchronizer is backing off.
`DataSourceUpdatesImpl.updateStatus` hands that null error to the outage
tracker, and `OutageTracker.recordError` dereferences it. The resulting
`NullPointerException` reaches the catch-all in the data source loop,
which logs "Unexpected error in data source" and closes the source
manager. No synchronizer starts again, so the client stops making
requests even after the cause (for example a 401) is resolved.

The tracker is enabled by default (`logDataSourceOutageAsErrorAfter` is
1 minute), so default configurations are affected. Setting it to `null`
avoids the crash.

Affected versions: 7.18.0 through 7.19.1 and `main`. The null-error call
was added with the RETRY orchestration change in 7.18.0 (#252). It is
not present in 7.17.3 or earlier.

## Change

`OutageTracker.trackDataSourceState` records an error only when the
update carries one. The outage is still started and its timeout still
scheduled, so an outage whose first report has no error is still timed.

This follows the `DataSourceUpdateSink.updateStatus` contract, which
documents `newError` as "information about a new error, if any". The
public status is unchanged: `updateStatus` already keeps the previous
`lastError` when it is given null, and errors reported earlier are
already counted.

The `INTERRUPTED` call with a null error in `FDv2DataSource` is left as
is. It asserts the state while every synchronizer is parked, and the
earlier errors are already in the status and the outage counts. Passing
the last error again would count it once per wake-up.

## Tests

Two new tests in `DataSourceUpdatesImplTest`, both failing with the NPE
without the change:

- A null update during an outage still reports the earlier error in the
outage log.
- A null update as the first outage report still schedules the timeout.

The full `lib/sdk/server` test suite passes locally. I did not run the
end-to-end 401 reproduction from the issue.

## Follow-ups (not in this PR)

- `FileDataSourceImpl` reports `INTERRUPTED` with no error when its
initial read fails, although it has the exception in hand.
- An unexpected exception in the `FDv2DataSource` loop ends the data
source permanently. Making that per-iteration would limit the impact of
future bugs of this kind.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Fixes a **NullPointerException** in the data source **outage tracker**
when `updateStatus` is called with `INTERRUPTED` and a **null**
error—behavior the FDv2 data source uses while synchronizers are backing
off.
> 
> **`OutageTracker.trackDataSourceState`** now calls `recordError` only
when `newError != null`. Outage detection, error accumulation for real
errors, and the delayed outage log timeout are unchanged: an outage can
still start and be timed even when the first or subsequent status update
carries no error.
> 
> Two unit tests cover null-error updates during an existing outage and
as the first interrupted report.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
6a773f5. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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