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

All attempts to open a WebSocket to connect to the database failed. #135

Open
pantharshit007 opened this issue Dec 29, 2024 · 0 comments
Open

Comments

@pantharshit007
Copy link

pantharshit007 commented Dec 29, 2024

I am using :

  • Turborepo
  • apps/nextjs 14
  • apps/node v18
  • apps/hono
  • app/vite
  • db (postgress with prisma)

My connection was working fine previously without this statement neonConfig.poolQueryViaFetch = true; but I just applied once in my hono prisma file and after that db calls are not working in node app when I am using flag = driverAdapter

why is that happening when It was working fine without it previously.

this is my setup for next and node I have a different one for hono

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

const prismaClientSingleton = () => {
  const useAdapter = process.env.USE_ADAPTER === "true";

  if (useAdapter) {
    neonConfig.poolQueryViaFetch = true;
    const pool = new Pool({ connectionString: process.env.DATABASE_URL });
    const adapter = new PrismaNeon(pool);
    return new PrismaClient({ adapter } as never);
    // log: process.env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
  }
  return new PrismaClient();
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

declare global {
  var prismaGlobal: PrismaClientSingleton | undefined;
}

const db = globalThis.prismaGlobal ?? prismaClientSingleton();

// in order to avoid creating too many prisma instances in development.
if (process.env.NODE_ENV !== "production") {
  globalThis.prismaGlobal = db;
}

export default db;
export type * as SchemaTypes from "@prisma/client";
export { Prisma } from "@prisma/client";

In prod my USE_ADAPTER is false its for local development since hono requires me to use the adapter and next works fine without it, but if I enable driverAdapter for hono in local this produces errors for next which leads me to use it (adapter) for next and node in local development also.

Update: If I ran node app solely with this neonConfig.poolQueryViaFetch = true; then it completed db calls and return data but when I am running all 4 apps to test, it fails when nextjs sends a REST req to node app with the error.

EXPECTED:
Node app should work without producing any error

CURRENT:
currently getting this error

All attempts to open a WebSocket to connect to the database failed. Please refer to https://github.com/neondatabase/serverless/blob/main/CONFIG.md#websocketconstructor-typeof-websocket--undefined. Details: fetch failed

If you want to look at the repo its, but it doesn't contain latest changes here

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

No branches or pull requests

1 participant