ReactiveX / ReactiveX/rxjs

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

Open
#2,445 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the WebSocketSubject.multiplex entry point and trace how subscriptions and unsubscriptions trigger the provided subMsg and unsubMsg callbacks. Reproduce the two-subscriber case described in the issue, then verify that subMsg is sent only for the first subscription and unsubMsg only after the last consumer unsubscribes.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.