Closed evnu closed 5 years ago
All of the dispatchers allow multiple subscriptions. It is something you have to handle in your logic yourself and not up to the dispatchers to enforce it. So the important question is: why are you subscribing twice when you don't want to? :)
why are you subscribing twice when you don't want to? :)
This came up during playing around and is of course a classic example of "stop hitting yourself". Nevertheless, I wonder for which case allowing a process to subscribe multiple times to the same source is useful. I think that this is something which does not generalize well over the different default dispatchers.
BroadcastDispatcher
: Must wait until a demand from all subscribers is received, which results in a possible deadlock if a process subscribes multiple times to a consumerDemandDispatcher
: Should work if a process is subscribing multiple times, but does not seem useful (I could not think of an example, maybe I am missing something here)PartitionDispatcher
: Subscribing multiple times could be useful to change the subscribed partitions over timeThat's a very good point. We can add a check for BroadcastDispatcher then. Could you please send a PR? Thanks!
Could you please send a PR?
Will do!
@josevalim Should subscription then be idempotent, or result in an error?
I don't know. I think an error is likely better because if you change dispatchers they won't be idempotent?
I don't know. I think an error is likely better because if you change dispatchers they won't be idempotent?
I would also prefer an error. I am not yet sure though how to propagate that error, especially as subscription can happen asynchronously.
Maybe the best we can do is log and discard it.
I would also prefer an error. I am not yet sure though how to propagate that error, especially as subscription can happen asynchronously.
Another option would be to make the subscription idempotent for BroadcastDispatcher
and simply ignore multiple subscriptions. With that, no change to the behaviour Dispatcher
would be necessary, and other dispatchers would not be affected.
EDIT: Forgot to refresh. Logging and discarding seems reasonable.
It appears that
BroadcastDispatcher
allows a single consumer to subscribe multiple times. This can result in subtle errors. In the following example, I subscribeC
multiple times toA
. Replacing the default dispatcher withBroadcastDispatcher
results in a timeout.Would it be possible to either allow a process to subscribe multiple times (make subscribing idempotent), or to otherwise throw an error?