Skip to content

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

Closed

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.

Activity

  1. ds300 commented on Oct 31, 2024

    @ds300
    Author

    oh wait actually my naive implementations of pause/resume did work correctly and I was just passing a badly formatted event string. I'll make a PR.

  2. porsager commented on Oct 29, 2026

    @porsager
    Owner

    v4's Workers socket implements pause and resume, so this error is gone. sql.subscribe needs a direct connection with a user allowed to replicate, and isn't part of the Workers test run yet.

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