Skip to content

Subscribe event topics on the peer's socket once it is open - #119

Closed
velis74 wants to merge 1 commit into
mainfrom
fix/events-wait-for-peer
Closed

velis74 wants to merge 1 commit into
mainfrom
fix/events-wait-for-peer

Conversation

@velis74

@velis74 velis74 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The event client polled a new topic over axios whenever it had no open peer. With a peer source
(createEventClient({ peer: () => currentPeer() })), a topic subscribed right after the muxws socket opened,
but before the source returned that peer, went to POST /events/poll. taskwire's attachViewsetEvents
subscribes its socket-only connection topic (taskwire:c.…) exactly then; the server refuses that topic over
REST (403), so taskwire marked its socket transport unhealthy and fell back to polling. The outcome depended on
which of the two resolved first.

Rule

When a peer is configured, topics are subscribed once the muxws connection is established; REST polling is only
for when there is no connection.

Case Behaviour
1. peer source pending (first subscription, or after a final close) a topic without a rev waits; no axios poll; subscribed on the socket once the peer is adopted and open
2. source throws or rejects every topic polled over axios on the existing ladder; the source is called again on the next rung; topics stay on axios until a peer is adopted
3. peer closes with willRetry: true no switch to axios; topics wait; on reconnect every topic is subscribed again and catches up by rev (gap poll over the peer)
4. peer closed for good topics with a rev polled over axios until the source returns a new peer, then subscribed on its socket; a bare peer stays on axios
5. peer not open yet (bare, or returned by the source) waits for its onReconnect
6. no peer axios, unchanged

subscribe().ready still resolves once the topic is followed (socket answer or poll answer); close() while a
topic waits rejects ready with Error('The event client is closed'); a subscription removed while waiting is
not subscribed; refresh() of a waiting topic is answered by the subscribe sent when the socket opens; a gap
of a waiting topic is caught up by that subscribe answer.

Changed existing tests (vue/events/client.spec.ts)

Behaviour on a reconnecting peer changed (case 3), so tests that used a retried close to reach the axios
fallback now use a close for good, and keep checking the same axios rules:

  • losing the peer … resumes the ladder on its base rung over axios, … while a rung polls over it …,
    … while the ladder waits …, drops a subscribe answer from the lost socket …,
    a gap poll that failed before the peer closed …, sends a gap poll over axios at once while the peer is closed,
    the check poll: sends nothing while the peer is closed; the ladder polls over axios: close() (willRetry)
    → closeForGood(); titles say "for good".
  • on reconnect subscribes every topic; an equal rev resumes …: no longer answers an axios poll while the peer
    is away; it now asserts that nothing is sent during the close.
  • polls over axios while the peer is not open, and subscribes once it reconnects → polls nothing over axios while the peer is not open yet, and subscribes once it opens (case 5).
  • peer source: polls over axios after the peer closes for good …: on adoption the client no longer sends a
    poll at once next to the subscribe; the test asserts only the subscribe and no axios call.

Tests

  • New unit tests for cases 1–6, close() and unsubscribe while waiting (waiting for the socket); all but the
    ones for unchanged behaviour (source throws, no peer) fail on main.
  • New scenario over a real muxws pair (vue/muxws-real.spec.ts): a socket-only topic subscribed before the
    source returns the open peer is subscribed on the socket, with axios answering 403 never called.
  • taskwire: vue/viewset-events, vue/muxws, vue/busy/base and packaging specs pass against this build, and
    a temporary test reproducing the klubis race (ViewsetEventsTransport with a pending peer source) fails on 0.16.5
    and passes on this build. No change in taskwire needed.
  • Demo e2e events.spec.ts (Chromium and Firefox) passes.

Version 0.16.6 (patch: bug fix).

A client with a peer no longer polls over axios while the peer source is
pending, while the peer is not open yet, or while it reconnects: its topics
wait and are subscribed on the socket when it opens, then catch up by rev.
A socket-only topic subscribed before the source returned the open peer was
polled over REST and refused. Axios carries the polls without a peer, after
the peer closed for good, and while the peer source throws or rejects.
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

✅ Incremental coverage — 96.9%

███████████████████░ 31 / 32 changed lines covered · threshold 70% · main → fix/events-wait-for-peer

File Coverage Covered Uncovered lines
⚠️ vue/events/client.ts 96.9% 31 / 32 1036
Total 96.9% 31 / 32
9 files not graded (2 ignored by pattern, 7 not source files)
File Reason
changelog.md not a source file
docs/api/vue-events.md not a source file
docs/guide/vue-events.md not a source file
package-lock.json not a source file
package.json not a source file
pyproject.toml not a source file
uv.lock not a source file
vue/events/client.spec.ts ignored by *.spec.*
vue/muxws-real.spec.ts ignored by *.spec.*

Coverage reports: coverage.json (coverage.py, 76 files) · coverage/clover.xml (clover, 17 files) — incremental-coverage-check v3.1.0

@velis74

velis74 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Closed: the connection topic is the only socket-bound topic; the fix goes into taskwire (subscribe the connection topic once the event client has an open socket). The event client's REST/socket rule stays unchanged.

@velis74 velis74 closed this Dec 1, 2026
@velis74
velis74 deleted the fix/events-wait-for-peer branch December 1, 2026 06:44
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

Successfully merging this pull request may close these issues.

1 participant