Skip to content

subscribe error on cloudflare: 'socket.resume is not a function' #975

Open
@ds300

Description

@ds300

I'm setting up a simple subscription in my Durable Object as follows:

const { unsubscribe } = await sql.subscribe('*:file:id=' + fileId, (row, info) => {
  // ...
})

and it's failing with this error

✘ [ERROR] Unexpected error during logical streaming - reconnecting TypeError: socket.resume is not a function

    at Duplex.read [as _read] (node_modules/postgres/cf/src/connection.js:865:16)
    at Readable.read (node-internal:streams_readable:452:12)
    at resume_ (node-internal:streams_readable:881:12)
    at null.<anonymous> (node-internal:process:14:28)

which points to this line

read() { socket.resume() },

Throwing the above error seems to send it into some kind of reconnection loop. If I log out the socket object I get

  EventEmitter {
   _events: [Object: null prototype] {
     error: [Function: error],
     close: [AsyncFunction: closed],
     drain: [Function: drain],
     connect: [Function: connected],
     data: [Function: data]
   },
   _eventsCount: 5,
   _maxListeners: undefined,
   readyState: 'open',
   raw: Socket {
     opened: Promise { [Object] },
     closed: Promise { <pending> },
     writable: WritableStream { locked: true, [state]: 'writable', [expectsBytes]: true },
     readable: ReadableStream {
       locked: true,
       [state]: 'readable',
       [supportsBYOB]: true,
       [length]: undefined
     }
   },
   writer: WritableStreamDefaultWriter {
     desiredSize: 1,
     ready: Promise { undefined },
     closed: Promise { <pending> }
   },
   reader: ReadableStreamDefaultReader { closed: Promise { <pending> } },
   connect: [AsyncFunction: connect],
   write: [Function: write],
   end: [Function: end],
   destroy: [Function: destroy],
   read: [AsyncFunction: read],
   ssl: false,
   host: '127.0.0.1',
   port: 6543,
   [Symbol(kCapture)]: false
 }

and looking at the cloudflare socket polyfill code it indeed seems like there is no 'pause'/'resume' implementations

function Socket() {

I tried playing around with providing naive implementations of these methods but I couldn't make the subscription work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions