Skip to content

Error: Channel $pubsub is not registered #4

Description

@henkelis

Hi,

I'm trialing using AnyCable in a node.js/React app. My intent is to use multiple channels for real-time data updates (I'm currently just using a single channel, 'lifting'). I also want to track a user's presence, so set up a simple pub/sub stream to cater for that (I'd use a channel but you don't yet support presence for channels). I also use the same mechanism on the server for server presence.

My node.js server provides an HTTP RPC server, and I run anycable-go with '--broker=memory'.

Everything works fine and I can see presence info for both client and server, until I refresh my client. My RPC disconnect handler gets called, but catches the error below. The rejection also causes my cable application disconnect to not get called.

RPC: Error: Channel $pubsub is not registered
    at CableApplication.findChannel (/server/node_modules/@anycable/serverless-js/dist/application/index.js:169:19)
    at CableApplication.handleClose (/server/node_modules/@anycable/serverless-js/dist/application/index.js:148:50)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async disconnectHandler (/server/node_modules/@anycable/serverless-js/dist/service/index.js:72:5)
    at async Server.requestListener (/server/src/server/rpc.ts:62:34)
Caught rejection: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object

If I log the payload.subscriptions in the service disconnectHandler, I can see that the generic $pubsub stream has been classed as a channel:

[
  '{"channel":"lifting"}',
  '{"channel":"$pubsub","stream_name":"presence"}'
]

$pubsub is not in the channels array, which causes the issue. If I register $pubsub as a channel the issue goes away, but then I can't use it for presence.

As I simple fix I've cloned the disconnect handler and filtered $pubsub out of the array - do you support using pub/sub alongside channels?

Mark.

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