Skip to content

fix: Publish the data source status before releasing ready waiters - #431

Merged
jsonbailey merged 4 commits into
mainfrom
jb/polling-spec-flake
Oct 5, 2026
Merged

jsonbailey merged 4 commits into
mainfrom
jb/polling-spec-flake

Conversation

@jsonbailey

@jsonbailey jsonbailey commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Follows #429, which fixed the same ordering problem on the unrecoverable-error path. Reworked from a spec-only change after @kinyoklion pointed out that the ordering itself was the bug — matching the change he has already merged in the Go SDK (go-server-sdk#442).

Describe the solution you've provided

1. Publish the status before releasing ready waiters

Three places raised the ready event before reporting a status, so a caller that returned from start could read a data_source_status_provider.status that did not yet reflect reality:

  • PollingProcessor#poll (FDv1) set the ready event and only then published VALID.
  • The FDv2 synchronizer loop had the same ordering.
  • The FDv2 initializer phase published no status at all on success. With initializers and no synchronizers, nothing ever published VALID, so the status stayed INITIALIZING for the lifetime of the data system.

All three now publish the status first and set the ready event afterwards. This is the same argument #429 made for the OFF path, applied to the success paths, and it matches the Java server SDK, where every readiness site reports status first (FDv2DataSource.java).

2. The success spec no longer needs to wait

This PR started as a spec-only fix that waited for the listener to be notified. With the ordering corrected that wait is unnecessary, so status is set to valid when data is received is back to its original form, unchanged from main.

Worth correcting one claim from the original description: delivery here is not asynchronous. The polling spec uses SynchronousExecutor, whose post just yields, so Broadcaster#broadcast calls listener.update inline. The distinction is which thread — inline on the poll thread, not the spec thread. That is why the old ordering was racy and why the new ordering makes the assertion deterministic: by the time @ready.set runs, the listener has already returned on that same thread.

3. The recoverable-error spec still needs its wait

verify_recoverable_http_error (408, 429, 503) keeps wait_for_count(2). That path publishes INTERRUPTED and never sets the ready event, so there is no event to reorder and the pre-existing ready.wait(1) was only passing time. ListenerSpy's mutex and condition variable stay for the same reason — without an event there is no happens-before for the cross-thread read, and a bare array appended from the poll thread and read from the spec thread is a real data race on JRuby.

wait_for_status is removed; wait_for_count is the only helper still used.

Describe alternatives you've considered

Keeping the spec-only fix. It would have made CI green while leaving an observable ordering problem in the SDK, which is the same trade #429 declined.

Hoisting update_status above the guards instead of introducing locals. In PollingProcessor#poll that would publish VALID before update_sink_or_data_store.init, so a store failure would report VALID then INTERRUPTED, and it would escape INITIALIZING before the write and so defeat the INTERRUPTED → INITIALIZING coercion in UpdateSink#update_status. In the FDv2 synchronizer loop it would move record_environment_id after the status publish. Go solves the latter by hoisting SetEnvironmentID out of the state switch entirely; that is a small deliberate behavior change and is left for a follow-up.

Additional context

Two further gaps from the same spec area are not addressed here, both from SDK-2980 (closed) under epic SDK-2993:

  • Requirement 1.1.5 clause 2 — when the initializer chain exhausts with only selector-less data, readiness should be raised then. Ruby gates readiness on a defined selector only. Java does this via an anyDataReceived flag; Go added it in go-server-sdk#441.
  • Requirement 1.2.11 / 1.1.8 — a delta or up-to-date response to a request that carried no selector must report Interrupted, apply no data, and not raise readiness. data_system/streaming.rb reports VALID for a transfer-none server intent unconditionally.

Both change when readiness fires rather than what the status says at that moment, so they are behavior changes with spec weight and want their own PR. There is no contract-test coverage for any of this today: the harness has no way to read an SDK's data source status, and cannot construct a payload with an absent selector.

Also not touched, deliberately:

  • The @disabled path raises readiness with no status. Java has no direct analogue.
  • The no-synchronizers and synchronizer-loop-exit paths raise readiness with no status. Java completes readiness with false and reports unexpected exhaustion; Ruby's ready event carries no success flag, so matching that needs an API discussion rather than a line change.

Validation

  • Rebased on bc6a166.
  • Full local suite: 1095 examples, 1 failure — spec/launchdarkly-server-sdk_spec.rb:5, the Bundler.require smoke test, which also fails at this branch's merge base in a worktree checkout and passes in a normal clone. Unrelated to these changes. The gap against CI is the redis, dynamodb, and consul store specs, which need backing services.
  • polling_spec.rb + fdv2_datasystem_spec.rb: 35 examples, 0 failures; looped 15 times with no failures.
  • Each new spec fails against the ordering it replaces. The polling spec asserts that the status listener does not observe an already-set ready event, and the initializer spec fails with expected: :valid, got: :initializing.
  • RuboCop clean on all five changed files.

Note

Overview
Ensures data source status is published before the ready event is signaled, so callers returning from start can read VALID (or the correct state) instead of stale INITIALIZING.

In FDv1 polling, PollingProcessor#poll now calls update_status(VALID) before @ready.set on first successful init. In FDv2, the initializer success path now reports VALID when a defined selector is present (previously it could stay INITIALIZING with initializer-only configs), and the synchronizer loop reports status before setting @ready_event.

Specs add ordering assertions for polling and FDv2, and ListenerSpy gains mutex/condition-variable wait_for_count for cross-thread status assertions on recoverable error paths where ready is never set.

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

@jsonbailey jsonbailey changed the title fix: Wait for status listener delivery in data source specs chore: Wait for status listener delivery in data source specs Sep 2, 2026
@jsonbailey
jsonbailey marked this pull request as ready for review September 2, 2026 21:50
@jsonbailey
jsonbailey requested a review from a team as a code owner September 2, 2026 21:50
Comment thread spec/impl/data_source/polling_spec.rb Outdated

expect(listener.statuses.count).to eq(1)
expect(listener.statuses[0].state).to eq(Interfaces::DataSource::Status::VALID)
# The poll thread sets the ready event before it publishes the VALID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason it is in this order? Go was also doing this and I just swapped them because you would expect the status to be set before the ready event.

@jsonbailey
jsonbailey force-pushed the jb/polling-spec-flake branch from ea48542 to b3fcc65 Compare September 9, 2026 21:58
@jsonbailey jsonbailey changed the title chore: Wait for status listener delivery in data source specs fix: Publish the data source status before releasing ready waiters Sep 9, 2026
@jsonbailey
jsonbailey marked this pull request as draft September 9, 2026 22:00
FDv1 polling and the FDv2 synchronizer loop both set the ready event
before publishing the VALID data source status. A caller that returned
from start could therefore read a status that did not yet reflect the
successful poll.

Both now publish the status first and set the ready event afterwards,
matching the OFF path fixed in #429.

The polling spec no longer needs to wait for the VALID status, because
the broadcaster notifies listeners inline on the poll thread and the
ready event is now set after that. The recoverable-error spec keeps its
wait: that path publishes INTERRUPTED and never sets the ready event, so
there is nothing to synchronize against.
The FDv2 initializer phase raised the ready event without reporting any
status, so a client configured with initializers returned from start with
a data source status that still read INITIALIZING. With no synchronizers
configured nothing ever published VALID, so the status stayed wrong for
the lifetime of the data system.

The initializer now publishes VALID before releasing ready waiters, the
same order as the synchronizer loop and matching the Java server SDK.
Publishing here does not duplicate the synchronizer's later VALID, which
UpdateSink#update_status drops as an unchanged state.
The status publish and the ready event sit next to each other, so the
order needs no explanation. In the FDv1 polling path the comment was
also above the ready event rather than above the publish four lines up,
so it described the wrong line.
@jsonbailey
jsonbailey marked this pull request as ready for review October 2, 2026 21:03
@jsonbailey
jsonbailey merged commit 0e224b9 into main Oct 5, 2026
11 checks passed
@jsonbailey
jsonbailey deleted the jb/polling-spec-flake branch October 5, 2026 13:18
jsonbailey pushed a commit that referenced this pull request Oct 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[8.18.1](8.18.0...8.18.1)
(2026-10-06)


### Bug Fixes

* Pass connect_timeout to the streaming SSE client
([#458](#458))
([f4a07af](f4a07af))
* Prevent close from hanging after a persistent store read fails
([91b7c9c](91b7c9c))
* Prevent flags from falling back to defaults when a deleted item has no
key
([afb9f3d](afb9f3d))
* Prevent flags from falling back to defaults when Consul holds one item
([8891226](8891226))
* Prevent the store availability poller from outliving the client
([91b7c9c](91b7c9c))
* Publish the data source status before releasing ready waiters
([#431](#431))
([0e224b9](0e224b9))
* Reuse an in-flight big segment status poll instead of querying twice
([#460](#460))
([96cca28](96cca28))

---
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 **8.18.1** by bumping
`LaunchDarkly::VERSION`, `.release-please-manifest.json`, and the
provenance example in `PROVENANCE.md`.
> 
> It adds a **8.18.1** section to `CHANGELOG.md` documenting bug fixes
already landed on main: streaming **connect_timeout** wiring,
persistent-store **close** and availability-poller lifecycle,
flag-evaluation fallbacks with deleted/Consul store edge cases, **data
source status** ordering before ready waiters, and deduplicating **big
segment** status polls. No SDK implementation files change in this
diff—only release bookkeeping.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
46d0611. 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>
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