Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ds300 opened this issue Oct 31, 2024 · 1 comment · May be fixed by #976
Open

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

ds300 opened this issue Oct 31, 2024 · 1 comment · May be fixed by #976

Comments

@ds300
Copy link

ds300 commented Oct 31, 2024

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.

@ds300
Copy link
Author

ds300 commented Oct 31, 2024

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.

@ds300 ds300 linked a pull request Oct 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant