Skip to content

fix: Prevent close from failing or hanging when called from a listener - #581

Open
keelerm84 wants to merge 2 commits into
mainfrom
mk/SDK-3566/close-from-listener
Open

keelerm84 wants to merge 2 commits into
mainfrom
mk/SDK-3566/close-from-listener

Conversation

@keelerm84

@keelerm84 keelerm84 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Closing the client from inside a listener now works on every thread the SDK calls listeners on.

  • FDv2 stop joined each of its threads, including the one running the listener. The join raised, so the data store and big segment store were left open. Stop now skips the current thread, which exits on its own.
  • A flag change listener called by an override update held the override sink lock, and close waited for that lock forever. Listeners are now notified after the lock is released.
  • The FDv1 file data source with watchdog called listeners on the observer thread, and stop joined that thread. Stop now skips that join.
  • A close during a store update no longer lets the update write to the closed persistent store.

Note

Overview
Fixes shutdown and lifecycle bugs when client.close() (or equivalent stop) is triggered from inside a listener callback on the same thread that is applying an update.

Thread self-join: FDv2.stop() and the file data source’s watchdog stop() now skip join() on the current thread so close/stop no longer raises or blocks when invoked from a flag-change or reload path.

Override sink deadlock: OverrideSinkImpl applies updates under its lock, then calls _notify_all after releasing the lock, so a listener can close the sink/client without waiting forever on the lock.

Store after close: The FDv2 Store tracks _closed and _should_persist() refuses writes once closed, so an in-flight apply that notified a closing listener does not persist to the persistent feature store.

Regression coverage adds listener-driven close scenarios for FDv2, override sink, file auto-update (watchdog and polling), and full LDClient (flag and data-store status listeners).

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

… listener

Listeners run on a data system thread, and stopping the FDv2 data system joined every one of its
threads, including that one. The join raised, so the data store and big segment store were left
open.
…stener

A flag change listener called by an override update held the override sink lock, and close waited
for that lock forever. Listeners are now notified after the lock is released.

The FDv1 file data source with watchdog called listeners on the observer thread, and stop joined
that thread. Stop now skips the join on that thread.

A close from a listener during Store.apply let apply write the change set to the closed persistent
store. The store now stops persisting after close.
@keelerm84
keelerm84 requested a review from a team as a code owner November 13, 2026 16:27

@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.

Risk: medium.

Automated risk review (dry run): Medium

This PR would not be automatically approved. Human approval required.

Why: This changes core client close/stop behavior across FDv2 thread join, the file data source observer thread, override-sink lock ordering, and persistent-store writes after close. Those interacting lifecycle paths are bounded by tests, but they are not a narrow low-risk change.

If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.

Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Dry-Run PR Approver

@cursor cursor Bot added the risk:medium label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant