neondatabase / serverless

Connect to Neon PostgreSQL from serverless/worker/edge functions

Home Page:https://www.npmjs.com/package/@neondatabase/serverless

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSockets connections issues arraybuffer?

webdeb opened this issue · comments

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:

// import { WebSocket as ws } from 'undici'; // waiting for release of https://github.com/nodejs/undici/pull/2106

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?

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?

@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:

  • Prisma is the main ORM
  • Building it into a cloudflare worker (next-on-pages) Edge runtime
  • Some of the routes are being build as a docker container (next js standalone)

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 });

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.

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

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