-
Notifications
You must be signed in to change notification settings - Fork 534
What should a Publisher do if it detects a duplicate subscription? #364
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
Comments
Yes. Do note, however, that a synchronous Subscriber may, because of visibility rules, not be able to detect double-subscriptions.
Great question!
Since 2:10 has been violated at this point, we are now operating in out-of-spec territory.
You need to signal onSubscribe first: 2:9.
This is borderline legal according to 2:9—depends on interpretation of
That doesn't take
Since "keeping track of existing Subscribers" will not solve the problem of infinite history, or the possibility of having the same Subscriber subscribed to different Publishers. Writing that out of the spec is probably backwards compatible. The problem with memory visibility for synchronous Subscribers still exist tho. I don't have time right now to check the TCK, what does it advise in the case of double-subscriber on the Publisher-side? |
This rule is not checked in the TCK since it's somewhat fuzzy as to what one should do if this situation is encountered ( I'm pretty sure the "4) ignore silently" is a bad idea, if a Publisher is in position to detect this, as you hint at @kjkrum, it should sound the alarms that a faulty part was detected IMO, one way or another. |
@ktoso ~~IMO there are three options:~
@kjkrum Is right, if the Publish knows that Subscriber has already been subscribed, issuing |
If the |
@kjkrum Apologies, you are of course right, see my edited comment above. |
It is generally impractical to detect this in an arbitrary
This dummy instance would be cancelled by the
Same rule but with the consequence that the subscriber may left "hanging" because no further events will arrive from the
This is a conservative way but also requires per-signal synchronization within the
Silently ignoring is usually not recommended because the situation is likely due to implementation bugs anyway. As an example, RxJava doesn't check for duplicates and treats all Allowing the same subscriber multiple times may be permissible provided the
§2.5 already requires this. |
@akarnokd Re §2.5, that's what I meant. :) |
@kjkrum Closing due to inactivity, please reopen if you think it hasn't been answered. :) |
Rule 2.5 mandates a
Subscriber
's response to an out-of-sequenceonSubscribe
caused by a faultyPublisher
or external misuse of theSubscriber
.There is no corresponding rule regarding a
Publisher
's response to a duplicate concurrent subscription caused by a faulty or misusedSubscriber
. APublisher
is not required to detect this because doing so would require thePublisher
to be stateful. However, if aPublisher
does detect it, what should it do?Some possibilities:
onSubscribe
with a dummySubscription
.onSubscribe
with the originalSubscription
.onError
, thereby canceling the originalSubscription
per 2.4.A strict reading of 2.12 prohibits the first two options. I propose that 2.12 be struck entirely, since it has evolved into a
Publisher
rule in theSubscriber
section. Replace it with a newPublisher
rule:And amend 2.5 to read:
Related discussions:
#63
#178
#202
The text was updated successfully, but these errors were encountered: