Repository navigation
fix: Prevent an FDv2 initializer result from being applied after close - #583
Merged
Merged
Conversation
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 changes FDv2 shutdown and in-flight initializer handling in ldclient/impl/datasystem/fdv2.py and ldclient/interfaces.py, plus polling after-close logging. Tests cover the new close path, but concurrent SDK lifecycle behavior is above Low.
Human review is needed, and no reviewers were assigned.
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
joker23
approved these changes
Nov 17, 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
When the client closed while an FDv2 initializer was still fetching, the data system kept going after close. It applied the initializer's result when the fetch returned, started the synchronizers, and logged the failed request as a warning or an exception.
Now close stops the initializer in progress. A result that arrives after close is not applied, and the synchronizers do not start. A polling result or error that arrives after close is not reported, and the error logs at debug.
Initializergets astop()method with a default implementation that does nothing. A custom initializer can implement it to end its fetch early. Close callsstop()only if the initializer has one, so an initializer that matches the protocol without the method still works.A polling request in progress still runs until it completes or times out, so close can still wait up to 5 seconds for it.
Note
Overview
Closing the client while an FDv2 initializer is still in
fetch()no longer applies its result or starts synchronizers.FDv2.stop()sets the stop event, optionally callsInitializer.stop()when present (tracked as_active_initializerunder the write lock), and the main loop bails out if shutdown happened during initialization.The
Initializerprotocol gains an optionalstop()with a no-op default so custom sources can unblockfetch(); shutdown usesgetattrso duck-typed initializers withoutstopstill work.PollingDataSourceV2 ignores poll results that finish after
stop()(sync loop breaks instead of yielding) and logs fetch/poll failures at debug during shutdown instead of warning/exception.Reviewed by Cursor Bugbot for commit f9b090a. Bugbot is set up for automated code reviews on this repo. Configure here.