Skip to content

Cloudflare Durable: persist peer.namespace in attachment (state.n) in _restore #187

@marr

Description

@marr

Summary

After namespaced pub/sub (e.g. #162), AttachedState includes optional n (connection namespace) and _restore reads namespace || state.n || "". If the namespace is not written into the serialized attachment before setAttachedState, hibernation / attachment-only restore can deserialize a state with no n, yielding an empty namespace and triggering getPeers"Websocket publish namespace missing." on close or pub/sub paths.

Suggested fix

In CloudflareDurablePeer._restore, after assigning state.i = peer.id (and any state.u updates), persist the namespace:

state.n = peer.namespace;
setAttachedState(ws, state);

This matches the intent of state.n on AttachedState and ensures the next serializeAttachment round-trip keeps the namespace across DO WebSocket hibernation.

Context

Consumers may work around this with a pnpm patch on dist/adapters/cloudflare.mjs (e.g. state.n = peer.namespace before setAttachedState). Upstream fix would allow dropping that patch.

Environment

  • crossws with Cloudflare Durable Objects adapter, ctx.acceptWebSocket, peer restored from attachment without a fresh upgrade request carrying namespace.

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