Repository navigation
Conversation
The static Combiner behind Or, And, Except and Xor updated its state under a lock but invoked the downstream callback after releasing it. When two sources changed on different threads, both changesets could be delivered to the observer at the same time, violating the Rx serialization contract. Operators downstream that rely on it can lose data: TakeUntil drops a notification that arrives while another is in flight, which is the intermittent "Or = Merged" mismatch seen in CrossCacheDeadlockStressTest. Route every source through one SharedDeliveryQueue, as DynamicCombiner already does. Updates from all sources are applied and delivered one at a time, and no lock is held while the observer runs, so a second producer enqueues and returns instead of overlapping the delivery in flight or blocking behind it. The regression test parks one thread inside the delivery of a change from the first source and changes the second source from another thread. Before the fix both overloads deliver the second change alongside the first.
This branch has not been deployed
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
The static combiner behind
Or,And,ExceptandXor(Combiner) can deliver two changesets to its observer at the same time, breaking the Rx serialization contract. Downstream operators that rely on that contract lose data.Root cause
Combiner.Updateapplied each source's changes and computed the combined changeset under_locker, then released the lock and called the downstream callback.OnNextwhile the first thread'sOnNextwas still running.TakeUntil, for example, silently drops anOnNextthat arrives while another is in flight.CrossCacheDeadlockStressTestshows this as an intermittentOr = Mergedmismatch:orCache(behindTakeUntil) occasionally ends up a few keys short ofmergedCache(noTakeUntil).Fix
Combinerroutes every source through oneSharedDeliveryQueue, the mechanismDynamicCombiner(the dynamic overloads) already uses._lockeris removed. The queue is disposed first, so nothing is delivered once disposal starts.Regression test
OrFixture.IntegrationTests.ChangesFromDifferentThreads_AreDeliveredSeriallycovers both the params and the collection overloads. It is deterministic: no timers or retries.On unmodified
main, both cases fail because the second change is delivered while the first is still in flight. The same interleaving through.TakeUntil(Observable.Never<Unit>())loses the second change entirely. With the fix, both cases pass.Behavior note
No public API changes. One thing does change: if another thread is mid-delivery, a write to a source can now return before its change reaches the combined subscriber, and the delivering thread delivers it. This matches the other queue-based operators. Before this change, such a write could be delivered concurrently with the one in flight.
Validation
CrossCacheDeadlockStressTest, 900 runs (300 in-process, 600 under CPU oversubscription): the original combiner failed once with theOrmismatch, the fixed one never did. The base rate is low, so the deterministic regression test is the real proof.