Skip to content

HandlerSubscriber is racy (at least as used from RxJava) #37

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

Closed
slandelle opened this issue Nov 27, 2017 · 2 comments
Closed

HandlerSubscriber is racy (at least as used from RxJava) #37

slandelle opened this issue Nov 27, 2017 · 2 comments

Comments

@slandelle
Copy link

I've been trying to hunt down a race condition that happens in AHC on Travis (can't reproduce locally).

AHC uses RxJava (2.1.7) as a reactive streams implementation for tests.

From io.reactivex.internal.subscribers.StrictSubscriber#onSubscribe:

actual.onSubscribe(this);
SubscriptionHelper.deferredSetOnce(this.s, requested, s);

HandlerSubscriber#onSubscribe schedule provideSubscription to be executed from the channel's EventLoop, that will trigger requesting the subscription. But SubscriptionHelper.deferredSetOnce can also request the subscription. As a consequence, we might be requesting the Publisher concurrently from multiple threads (the calling thread and the event loop one), which causes chunks to be written out of order.

I have no idea if it's a RxJava bug, or if StrictPublisher behaves according to the spec.

cc @jroper

@slandelle
Copy link
Author

I have this solution on my side: AsyncHttpClient/async-http-client@391b4d8

I don't know if the issue is related to RxJava's reactive streams implementation and if it would also happen with Akka.

@jroper
Copy link
Member

jroper commented Jan 22, 2019

I have no idea what RxJava is doing here, but the subscription passed to onSubscribe on a subscriber is a private contract between that subscriber and what passed it to it. So if something jumps in the middle, and captures the subscription, and starts playing with it itself, that's completely illegal according to the spec. So, if SubscriptionHelper.defferedSetOnce does invoke request, but then forwards onNext provided elements on to the subscriber without checking whether the subscriber it's forwarding to itself has invoked request, that's a bug.

@jroper jroper closed this as completed Jan 22, 2019
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

No branches or pull requests

2 participants