Skip to content

WebSocket transport does not allow healing connections #58

Closed

Description

@tom-sherman

In other words, the session does not allow the websocket to reopen after it closes - the session is immediately aborted.

A way to reproduce this is with using reconnecting-websocket or partysocket.

import { newWebSocketRpcSession } from "capnweb";
import { WebSocket as ReconnectingWebsocket } from "partysocket";

const sesssion = newWebSocketRpcSession(
  new ReconnectingWebsocket("ws://localhost:8001/rpc")
);

Is this intentional behaviour of the default websocket transport? If so, would a new ReconnectingWebsocket transport be acceptable or should this be left to userland? I'm not sure what your thoughts are about adding new transports to core.

Activity

  1. kentonv commented on Sep 27, 2025

    @kentonv
    Member

    Hmm, what are you imagining should happen to the session state on a reconnect? That is, what happens to stubs that were passed over the connection before the disconnect?

    Possibilities include:

    • They are all just broken. Only the "main" stub is reconnected.
    • The client reconnects to the same server as before, where the session state still exists in memory, so that it can be resumed without losing anything.
    • On reconnect, the system automatically recreates all stubs by replaying the same calls that created them the first time.
  2. LoganDark commented on Oct 17, 2025

    @LoganDark

    I can't even tell when the WebSocket connection breaks. If I could, then I'd be able to call newWebSocketRpcSession again, get a new stub, and do my own replay.

    I can listen to the WebSocket's close and error events, but that doesn't catch all cases where the (private) transport calls #recievedError.

    I had to make my own transport for the server side (because of Bun), so it looks like I'll have to do that for the client too.

    Edit: Looks like onRpcBroken can be used for this.

  3. kentonv commented on Oct 17, 2025

    @kentonv
    Member

    Yes, you can use onRpcBroken() to detect when the connection is lost. And from that you should be able to implement various approaches to handling this.

    I could imagine having something more batteries-included, but it's not entirely clear what the behavior should be (see my previous comment).

  4. locked and limited conversation to collaborators on Oct 30, 2025
  5. converted this issue into a discussion #98 on Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions