Skip to content

mediator-transport: WS-upgrade diagnostics + inbound resilience (0.4.2) - #2

Merged
stormer78 merged 2 commits into
mainfrom
ws-connect-diagnostics
May 31, 2026
Merged

mediator-transport: WS-upgrade diagnostics + inbound resilience (0.4.2)#2
stormer78 merged 2 commits into
mainfrom
ws-connect-diagnostics

Conversation

@stormer78

Copy link
Copy Markdown
Contributor

Summary

Two robustness improvements to MediatorSession, released as 0.4.2 (additive, within the existing ^0.4.1 range).

1. Actionable diagnostics for failed WebSocket upgrades

A failed upgrade used to collapse into one opaque WebSocket failed to open. The browser error event is deliberately detail-free, so we now settle on the close event and surface what it carries:

  • Maps the RFC 6455 close code to a cause — 1008 → mediator auth/ACL reject (distinct from the target VTA's ACL), 1006 → refused upgrade / TLS / a proxy not passing the Upgrade header (a CORS-blocked cross-origin upgrade lands here), 1015 → TLS failure.
  • Decodes the bearer token's exp to flag a born-expired / clock-skewed token.
  • Attaches structured code / reason / endpoint fields to the error.
  • Adds connectTimeoutMs (default 15s) so a silently-dropped upgrade fails fast instead of hanging.

2. Per-frame inbound resilience

A single bad inbound message (undecryptable, malformed, unknown sender, or a throw in dispatch) was silently dropped. Now:

  • New onError hook (default console.warn); _onFrame is fully defensive (decode / unpack / dispatch each in their own try/catch with a short frame fingerprint).
  • One poison message is logged and skipped — the session keeps delivering the rest of the queue instead of getting stuck.

Note: undecryptable frames are still not auto-ACKed (draining them risks the ack-storm the code avoids for mediator-originated frames), so a permanently-bad message can still redeliver across reconnects. Flagged as a deliberate follow-up.

Tests

  • New: 1008/1006 close-code hints, born-expired bearer, connect timeout, and a poison-frame test (two bad frames logged, the good frame after them still resolves).
  • Full suite: 203 pass, 0 fail.

🤖 Generated with Claude Code

stormer78 added 2 commits May 31, 2026 00:54
The connect path collapsed every WebSocket upgrade failure into one
opaque "WebSocket failed to open". The browser `error` event is
deliberately detail-free; the `close` event that follows carries the
`code`/`reason` that says WHY — and the old code discarded it by
settling on `error` first.

Now settle on `close`, map RFC 6455 codes to causes (1008 → mediator
ACL/auth reject, distinct from the target VTA's ACL; 1006 → refused
upgrade / TLS / proxy not passing Upgrade), decode the bearer token's
`exp` to flag a born-expired/skewed token, attach structured
`code`/`reason`/`endpoint` fields, and add a connect timeout so a
blackholed upgrade fails fast instead of hanging forever.

Adds 4 tests (1008+ACL hint, 1006+proxy, expired bearer, timeout).

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
A single bad inbound message (undecryptable, malformed, unknown sender,
or a throw in dispatch) was silently dropped. Add an `onError` hook
(default console.warn) and make `_onFrame` fully defensive — decode,
unpack, and dispatch each in their own try/catch with a frame
fingerprint — so the session logs the bad message and keeps delivering
the rest of the queue instead of getting stuck.

Bumps to 0.4.2 (with the WS-upgrade diagnostics from the prior commit)
and adds a CHANGELOG entry.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
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