neondatabase / serverless

Connect to Neon PostgreSQL from serverless/worker/edge functions
https://www.npmjs.com/package/@neondatabase/serverless
MIT License
318 stars 11 forks source link

WebSockets connections issues arraybuffer? #77

Closed webdeb closed 2 weeks ago

webdeb commented 2 months ago

Hello, I am stumbeling on an periodical error, something like that:

Error ErrorEvent {
  [Symbol(type)]: 'error',
  [Symbol(kTarget)]: WebSocket {
  [Symbol(kEvents)]: SafeMap(4) {
  'error' => <ref *1> {
  size: 1,
  next: Listener {
  next: undefined,
  previous: [Circular *1],
  listener: [Function],
  flags: 0,
  callback: [Function]
}
...
..

},
  [Symbol(ready state)]: 0,
  [Symbol(binary type)]: 'arraybuffer'
},
  [Symbol(kIsBeingDispatched)]: false
}
 ⨯ node_modules/.pnpm/@neondatabase+serverless@0.9.1/node_modules/@neondatabase/serverless/index.mjs (1343:0) @ eval

Had to add a console.log to see it actually..

Anyway, seems to be ws related, and wanted to ask, if this is something known, because I found this comment in the codebase: https://github.com/neondatabase/serverless/blob/b39a2dddb73f8c86271f9f25b3e33e63278e3cc9/dist/node/index.mjs#L6

It looks like undici already merged the fix, and btw some hours ago they published a new version. If its not planned to use it immediately, I would like to try it out, should I just link this repo locally and try out?

jawj commented 2 months ago

Thanks for your report.

It's a unfortunately opaque error message! If it persists, please let us know what platform you're running this on. A minimal reproduction would also be very helpful.

That particular undici fix was eventually merged a while back, so in principle it should be fine now to use either ws or undici in that file.

Is it possible your issue is down to a recent problem with pnpm?

webdeb commented 2 months ago

@jawj can you give me a brief explanation how to use / build & deploy the package locally? I would be able to track the error more precisely.

The context is the following:

I am using the latest version of the package on npm 0.9.1 (0.9.2 is not deployed btw, if that matters) Node 20.2.0 (I'll try to switch to 18.20.2) pnpm 8.6.2

This is how the client is instantiated

import { PrismaClient } from "@/prisma/generated/client";
import { Pool } from "@neondatabase/serverless";
import { PrismaNeon } from "@prisma/adapter-neon";

const pool = new Pool({ connectionString: process.env.POSTGRES_URL });
const adapter = new PrismaNeon(pool);
export const prisma = new PrismaClient({ adapter });
jawj commented 2 months ago

OK. Clone https://github.com/neondatabase/serverless and take a look at DEVELOP.md.

After making changes, run npm run export, cd to dist/npm and run npm link.

In another project, run npm link @neondatabase/serverless to use your local version.

jawj commented 2 weeks ago

@webdeb Did you ultimately figure this out? Assuming the problem is not on our side, I'll go ahead and close the issue.

webdeb commented 2 weeks ago

@jawj we went another infrastructure path atm. Thank you for taking time on this.