Do not merge fix: stop the FDv2 synchronizer rotation from spinning (fixes testDebugUnitTest OOM) - #384
Draft
abelonogov-ld wants to merge 2 commits into
Draft
Do not merge fix: stop the FDv2 synchronizer rotation from spinning (fixes testDebugUnitTest OOM)#384abelonogov-ld wants to merge 2 commits into
abelonogov-ld wants to merge 2 commits into
Conversation
The recovery tests shared one MockQueuedSynchronizer instance across every factory call. Because FDv2DataSource closes the previous synchronizer when it switches, recovery rebuilt an already-closed mock, which reported SHUTDOWN immediately and made the synchronizer loop spin between two dead sources. The spin filled the log capture until the test JVM ran out of memory, which is how testDebugUnitTest failed in CI. Co-authored-by: Cursor <cursoragent@cursor.com>
The synchronizer loop advanced to the next source as soon as a session ended, with no lower bound on how long a session had to last. A source that reports SHUTDOWN as soon as it is built therefore let the loop rotate at CPU speed: over a million synchronizers were built in 1.5 seconds in a test that reproduces it. Rotation now pauses when a session ends sooner than it plausibly could have connected, growing the pause up to 30 seconds while sessions keep ending immediately and resetting once one of them lasts. The pause waits on shutdownCause instead of sleeping, so a stop() during it is acted on at once. Co-authored-by: Cursor <cursoragent@cursor.com>
abelonogov-ld
marked this pull request as draft
August 12, 2026 23:18
1 task
3 tasks
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
FDv2DataSourceTest.recoveryResetsToFirstAvailableSynchronizerfailed CI withjava.lang.OutOfMemoryError, breakingtestDebugUnitTeston the 5.14.0 release run. There were two problems: the tests misused the mocks, and the data source turned that misuse into a busy loop instead of a plain failure.Tests. Three recovery tests shared a single
MockQueuedSynchronizerinstance across every call to their synchronizer factory.FDv2DataSourcecloses the previously active synchronizer when it switches sources, so when the recovery condition reset the source index and rebuilt the first synchronizer, the factory handed back an already-closed mock, which reportsSHUTDOWNfromnext()immediately. Each factory now builds a fresh mock, which is what real synchronizer factories do.Data source. The rotation loop advanced to the next source as soon as a session ended, with no lower bound on how long a session had to last. Two closed mocks therefore rotated as fast as the CPU allowed, writing about three log messages per iteration into the unbounded list in
LogCaptureuntil the test JVM exhausted its heap. Rotation now pauses when a session ends sooner than it plausibly could have connected, growing the pause up to 30 seconds while sessions keep ending immediately and resetting once a session lasts. The pause waits onshutdownCauserather than sleeping, so astop()during it is acted on right away.The same hazard existed without any mocks: a single configured synchronizer that reports
SHUTDOWNas soon as it is built would have spun this loop forever in a real app.Verification
synchronizersThatShutDownImmediatelyDoNotSpinbuilds two synchronizers that shut down immediately and asserts the rotation stays rate limited. Without the production fix it reports 1,243,438 synchronizers built in 1.5 seconds; with it, three.mainthe two recovery tests each ran for the full 10sawaitApplyCounttimeout, since a closed mock can never deliver the third expected apply, and that 10s of busy-looping is what exhausted the heap under CI's slower conditions. They now finish in ~3.0s, matching the intended 1s fallback plus 2s recovery.:launchdarkly-android-client-sdk:testDebugUnitTestpasses locally: 729 tests, 0 failures.:launchdarkly-android-client-sdk:lintis clean.Note for reviewers
The inner loop that consumes results from a single synchronizer is still paced entirely by that synchronizer's
next()future, so a source that resolvesnext()instantly and forever (for example one that reportsINTERRUPTEDwith no internal backoff) can still spin. That felt like the source's contract rather than the orchestrator's, so I left it alone; happy to add a bound there too if you'd rather the data source defend against it.Test plan
build-and-publish/testDebugUnitTestpassesNote
Overview
FDv2 synchronizer rotation no longer advances to the next source the instant a session ends. If a synchronizer session lasts less than 500ms (e.g. immediate
SHUTDOWN),FDv2DataSourcewaits before building the next one, with a pause that doubles up to 30s while short sessions keep happening and resets once a session runs longer. The wait usesshutdownCausewith a timeout sostop()can unblock immediately instead of sleeping.Tests were updated so synchronizer factories return a new mock on each build (reusing one instance after
close()only yieldsSHUTDOWNand triggered the spin). A new testsynchronizersThatShutDownImmediatelyDoNotSpinasserts rotation stays bounded when every synchronizer shuts down on firstnext().Reviewed by Cursor Bugbot for commit 69f18b0. Bugbot is set up for automated code reviews on this repo. Configure here.