fix: stop accumulating WhenAny continuations on the Conditions aggregate#562
Merged
Conversation
kinyoklion
approved these changes
Jun 22, 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.
The FDv2 data system's
Conditions::GetFuture()previously returned the same shared future to every iteration ofRunSynchronizerNext, so each iteration'sWhenAny(cond_future, next_future).Then(...)appended a callback to the shared future'scontinuations_vector. On a healthy primary streaming changesets without ever firing fallback/recovery, those continuations accumulated for the synchronizer's lifetime.Conditions::GetFuture(token)now returns a fresh Future per call.CancellationSourceafter the WhenAny resolves.Conditions.Analogous to launchdarkly/java-core#163.
Note
Medium Risk
Touches FDv2 orchestration and async cancellation ordering (locks around
CancellationCallback); behavior change is localized but long-running streaming paths depend on correct cleanup.Overview
Fixes unbounded growth of
WhenAnycontinuation callbacks during long-lived primary streaming, where eachRunSynchronizerNextloop reused one sharedConditionsfuture.Conditions::GetFuturenow takes aCancellationTokenand returns a new future per call. A single internal aggregate listener still watches the first condition to fire; when it resolves, it fans out to all pending per-call promises.Closealso drains any still-pending waiters withkCancelled.Callers (notably
FDv2DataSystem::RunSynchronizerNext) create a per-iterationCancellationSource, pass its token intoGetFuture, and cancel afterWhenAnycompletes so the pending entry and its promise/continuations can be dropped. Token cancellation removes the waiter from the pending list if the race finishes early.Tests updated to pass a
CancellationTokenintoGetFuture.Reviewed by Cursor Bugbot for commit af09001. Bugbot is set up for automated code reviews on this repo. Configure here.