Skip to content
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

Observable multiplexed from WebSocketSubject sends subMsg/unsubMsg to the server per every subscription #2445

Open
mpodlasin opened this issue Mar 5, 2017 · 5 comments

Comments

@mpodlasin
Copy link
Contributor

mpodlasin commented Mar 5, 2017

Hi.

Assume I get an Observable from multiplexing a WebSocketSubject:

const obs = ws.multiplex(() => "sub", () => "unsub", message => true);

I would assume that "sub" message would be sent to the server only on the first subscribtion. On second subscription server already pumps values to the client, so there is no need to send "sub" second time.

Conversely "unsub" should be sent when last consumer unsubscribes, but not when there is still someone subscribing.

And yet currently "unsub" will be sent whenever any consumer unsubscribes from an Observable. That means server needs to have its own counting logic (how many subscriptions it has on the client), otherwise whenever any consmer unsubscribes, all other consumers will stop getting messages, since server will stop pumping them (it got "unsub", so it assumes no one wants to listen).

So there is potential bug with sending "unsub" as well as unneccessary sending of "sub" (which may actually confuse server as well).

A bug?
A feature? If so, why?

@mpodlasin mpodlasin changed the title Observable multiplexed from WebSocketSubjects sends subMsg/unsubMsg to the server per every subscription Observable multiplexed from WebSocketSubject sends subMsg/unsubMsg to the server per every subscription Mar 5, 2017
@ImAHungover
Copy link

any answer?

@ImAHungover
Copy link

@benlesh please help us :)

@Suizi11
Copy link

Suizi11 commented Oct 4, 2018

I completely agree with @mpodlasin . I expected the same behavior.

I would say it's more like a feature than a bug ;)

@erincarignan
Copy link

erincarignan commented Oct 17, 2018

+1
And thanks @mpodlasin for the documentation. Huge help.

Is there a workaround for this issue that doesn't involve having the server keep track of subscribers?
I've posted a question on StackOverflow, here.

The documentation mentions using publish(), but I've tried variations of both publish and share, and find that the unsubscribe message either

  1. gets sent to the server with every unsubscribe
  2. or never get sent at all (using shareReplay(1))

@paflov
Copy link

paflov commented May 13, 2020

For everyone landing here find a solution to user multiple subscriptions to multiplexed channel:

use .pipe(share());on the result.

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

5 participants