Repository navigation
chore: Wait for the replacement flag in the FDv1 fallback spec - #457
Merged
Merged
Conversation
The spec released its wait once two flag change events had arrived, then asserted that the collected keys included the FDv1 replacement flag. Applying the FDv1 payload replaces the initializer's data, so it reports the removed flag as well as the added one. The full sequence is always initialflag, initialflag, fdv1replacementflag, which means the count of two was reached before the awaited flag arrived, every run on every platform. The assertion passed only because the third event usually landed in the window between the wait returning and the keys being read. JRuby's real parallelism loses that race often enough to fail CI. The wait now keys on the replacement flag itself. The collection is a Concurrent::Array because the data source thread appends to it while the spec thread reads it.
kinyoklion
approved these changes
Oct 2, 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.
Requirements
Related issues
Fixes the remaining JRuby failure that #429 deliberately left out of scope. There is no production code change.
#429 attributed this example to a lost wakeup —
changed = Concurrent::Event.newbeing replaced after the firstwaitreturned. That is not what is happening; the current example has a single event and a single wait. The cause is the gate.Describe the solution you've provided
spec/impl/data_system/fdv2_datasystem_spec.rb, "FDv1 fallback with initializer / falls back to FDv1 and replaces initialized data" released its wait once two flag change events had arrived:and then asserted that the collected keys included
fdv1replacementflag.Applying the FDv1 payload replaces the initializer's data, so it reports the removed flag as well as the added one. Instrumenting the example shows the sequence is always:
So the count of two is reached on
initialflagtwice — on every run, on every platform — andchanged.setfires from that second delivery while the third is still queued.Three threads are involved.
FDv2owns aConcurrent::SingleThreadExecutorshared by all four of its broadcasters (impl/data_system/fdv2.rb), andBroadcaster#broadcasthands each listener call to it viaexecutor.post(impl/broadcaster.rb). So the listener runs on that executor thread, not on the data source thread and not on the spec thread. The executor serializes the three deliveries against each other, but it does nothing to stop the spec thread from waking between them — which is exactly what happens: the spec thread returns fromchanged.wait(3)and evaluateschanges.mapwhile the third delivery is still pending.CRuby's GIL means the executor thread almost always completes the third delivery before the spec thread is rescheduled, so the example passes there. JRuby runs the two threads in parallel and loses the race often enough to fail CI. The observed failure matches:
The gate now keys on the awaited flag rather than on a count, so the wait cannot return before that flag has been appended:
That is the whole fix. The append precedes the
setwithin a single listener invocation, so a spec thread returning fromwaitis ordered after every append — a happens-before edge rather than an incidental GIL win.changesalso becomes aConcurrent::Array. This is defensive hardening, not part of the fix: with the gate above, the awaited flag is the last event and nothing is appending while the assertions run. It is there because the collection is written from the executor thread and read from the spec thread, so a future change to the gate — or an additional change event — should not reintroduce an unsynchronized cross-thread read. On JRubyConcurrent::ArrayincludesJRuby::Synchronized; on CRuby it is a bare::Arraysubclass.Describe alternatives you've considered
Raising the gate to
changes.length >= 3. It works, and the sequence is deterministic, but it re-encodes the number of events the FDv1 replacement happens to produce. Keying on the flag the assertion is about survives a future change to how replacements are reported.Leaving
changesas a plain array. The gate alone makes the example correct, and the five sibling examples in this file use plain arrays.Concurrent::Arrayis kept because this example's collection is the one being written from a background executor while the spec thread reads it.Tagging the example
flaky: true, the mechanism this repo already uses forrequestor_spec,event_sender_spec, andldclient_end_to_end_spec. That would have hidden a genuine test bug and cost JRuby coverage of the FDv1 fallback path.Additional context
The other timing-sensitive concern #429 raised for this file — roughly two dozen waits of 1–3 seconds — is unchanged here. The
:218example it also saw fail is untouched; I have not reproduced that one.#431 is currently red on JRuby for this same example. Once this merges, rebasing that branch should clear it without any change to its own code.
Validation
spec/impl/data_system/fdv2_datasystem_spec.rb: 18 examples, 0 failures; 15 consecutive runs of the affected example all passed.