Skip to content

fix(perry-ext-ws): #813 — deliver server-level wss.on('message'/'close') events#814

Merged
proggeramlug merged 2 commits into
mainfrom
fix/813-extws-server-handlers
May 15, 2026
Merged

fix(perry-ext-ws): #813 — deliver server-level wss.on('message'/'close') events#814
proggeramlug merged 2 commits into
mainfrom
fix/813-extws-server-handlers

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

Fixes #813 — the residual root cause behind #746 that persisted after the #747 fastify-pump fix (v0.5.904) shipped in v0.5.912.

perry-ext-ws only delivered message/close events to per-client listeners (WS_CLIENT_LISTENERS). A server-level wss.on('message', (ws, data) => …) / wss.on('close', (ws) => …) handler — valid in perry-stdlib::ws and used by perry-hub — never fired. (connection already worked because it dispatches via listeners_on_server.) The v0.5.572 perry-stdlib→perry-ext port dropped this server-level path.

Two defects, both fixed (mirroring crates/perry-stdlib/src/ws.rs)

  1. drive_server_client_io race-guard — the Implement node:http / node:https / node:http2 + WebSocket upgrade for npm-ecosystem HTTP server compat #577 Phase 4 has_listener guard only checked the per-client map, so an inbound frame for a server-only handler was parked on c.messages forever and no PendingWsEvent::Message was ever pushed. Now also checks the parent WsServerHandle (WS_CLIENT_PARENT_SERVERlisteners_on_server(sh, "message")).
  2. js_ws_process_pending Message/Close arms — no parent-server fall-through. When per-client listeners are empty, fall through to the parent server's listeners: messagecall2(ws_id, data), closecall1(ws_id), matching perry-stdlib::ws.

Validation

  • cargo check -p perry-ext-ws --release — clean.
  • End-to-end: perry-hub recompiled on Linux x86_64 with v0.5.912 + this patch. Before: wss.on('connection') fired but wss.on('message') never did (no Worker connected). After: connection, server-level message (worker_hello → Worker connected), and real workers (oakhost-tart, azure-sign-win) all connect and round-trip correctly. Hub has been serving production traffic on this build.

Notes / follow-ups

  • The 'error' server fall-through is intentionally not included here (perry-stdlib uses server "client_error" for per-client errors vs "error" for ServerError; the hub doesn't depend on it). Worth a parity pass separately.
  • A regression test (server-only wss.on('message') echo + single-frame client) would lock this down — happy to add if you'd like it in this PR.

Closes #813. Refs #746, #747.

…e') events

The v0.5.572 perry-stdlib→perry-ext-ws port dropped the server-level
listener path. perry-ext-ws only delivered `message`/`close` events to
*per-client* listeners (`WS_CLIENT_LISTENERS`), so a server-level
`wss.on('message', (ws, data) => …)` / `wss.on('close', (ws) => …)`
handler — valid in perry-stdlib::ws and used by perry-hub — never fired.

Two defects, both fixed here mirroring perry-stdlib::ws semantics:

1. `drive_server_client_io` race-guard: `has_listener` only consulted
   the per-client map, so an inbound frame for a server-only handler
   was parked on `c.messages` forever and no `PendingWsEvent::Message`
   was ever pushed. Now also checks the parent `WsServerHandle` via
   `WS_CLIENT_PARENT_SERVER` → `listeners_on_server(sh, "message")`.

2. `js_ws_process_pending` `Message`/`Close` arms had no parent-server
   fall-through. When per-client listeners are empty, fall through to
   the parent server's listeners — `message` → `call2(ws_id, data)`,
   `close` → `call1(ws_id)` — matching `crates/perry-stdlib/src/ws.rs`.

This was the residual root cause behind #746 (closed assuming a
Linux-only pure-WS symptom; it is neither Linux-specific nor a pump
issue) that persisted after the #747 fastify-pump fix (v0.5.904).

Validated end-to-end: perry-hub recompiled on Linux with this patch
on v0.5.912 — `wss.on('connection')`, server-level `wss.on('message')`
(worker_hello → "Worker connected"), and real workers all fire
correctly. `cargo check -p perry-ext-ws --release` clean.

Closes #813. Refs #746, #747.
@proggeramlug proggeramlug merged commit fe2692e into main May 15, 2026
9 checks passed
@proggeramlug proggeramlug deleted the fix/813-extws-server-handlers branch May 15, 2026 20:02
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.

perry-ext-ws: server-level wss.on('message'/'close') handlers never fire — frames parked on c.messages (the real #746 root cause)

1 participant