-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mono violates Reactive Streams rule 2.7 #3117
Comments
@dkhalanskyjb, it is a known issue and it is definitely on the road map ( we do have racing on requests methods). Also, it is in the progress of fixing. Not going to come soon in 3.5 but stay tuned ( the main reason why is that the scope is too wide so we can not rework everything at once ) Also, one thing to clarify. Serialization here is about the |
Also, please see related PR in RS spec (see reactive-streams/reactive-streams-jvm#489) |
superseded by #3120 |
Hi, what is the issue we can keep track of regarding changes in 3.5? |
Thanks! |
The subscription here checks the rule https://github.com/reactive-streams/reactive-streams-jvm/blob/v1.0.3/README.md#2.7, which stipulates that the subscribers have to call
request
andcancel
in a serialized manner. In practice, this means that, if cancellation may happen in parallel, when implementing a subscriber, one has to guard the calls torequest
andcancel
with locks.Example of such safety measure:
The problem is, with
Mono
, this measure is not sufficient, because the lock arounds.request
is useless:Mono
will first callonSubscribe
, remember the requested number of elements, and only then call therequest
on the actualSubscription
, by which time, the lock is no longer held.Expected Behavior
When a
Subscription
provided byMono
is accessed in a serialized manner,Mono
should also guarantee that the subscription passed toCoreSubscriber
in itssubscribe
method will also be accessed in a serialized manner.Actual Behavior
Even when a subscriber calls
cancel
andrequest
in a serialized manner, it is possible to have aMono
that forwards these calls in such a way thatSubscription
is not accessed in a serialized manner.Steps to Reproduce
Run https://github.com/Kotlin/kotlinx.coroutines/blob/b0d1aaee024794116a62e161cbd3eb14016d12ed/reactive/kotlinx-coroutines-reactor/test/MonoAwaitCancellationStressTest.kt, observe failures filling the build log. Optionally, replace the test
Mono
with the more realistic version provided above.The text was updated successfully, but these errors were encountered: