Observable multiplexed from WebSocketSubject sends subMsg/unsubMsg to the server per every subscription
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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