Cannot perform I/O on behalf of a different request. I/O objects (such as streams, request/response

I'm running into this issue with Neon, Next-on-pages (Cloudflare) with the new edge (without accelerate) release. I see the documentation here (https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-vercel#neon) that says I should setup the prisma client via:
const neon = new Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaNeon(neon)
const prisma = new PrismaClient({ adapter })
const neon = new Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaNeon(neon)
const prisma = new PrismaClient({ adapter })
However I would like to use this across many files, how should I setup the singleton pattern (or do I even need to?) This is what's making me think that it's an issue on how I'm connecting up to the DB - (https://community.cloudflare.com/t/error-cannot-perform-i-o-on-behalf-of-a-different-request/617112/2) Here is my code in /db.ts
const neon = new Pool({ connectionString: process.env.DATABASE_URL });
const adapter = new PrismaNeon(neon);
const prisma = new PrismaClient({ adapter });

export default prisma;
export * from "@prisma/client";
const neon = new Pool({ connectionString: process.env.DATABASE_URL });
const adapter = new PrismaNeon(neon);
const prisma = new PrismaClient({ adapter });

export default prisma;
export * from "@prisma/client";
Any help would be much appreciated! (And the full error coming from CF workers):
cannot perform i/o on behalf of a different request. i/o objects (such as streams, request/response bodies, and others) created in the context of one request handler cannot be accessed from a different request's handler. this is a limitation of cloudflare workers which allows us to improve overall performance.
cannot perform i/o on behalf of a different request. i/o objects (such as streams, request/response bodies, and others) created in the context of one request handler cannot be accessed from a different request's handler. this is a limitation of cloudflare workers which allows us to improve overall performance.
Prisma
Deploy to Vercel Edge Functions & Middleware
Learn the things you need to know in order to deploy an Edge function that uses Prisma Client for talking to a database.
1 Reply
mr nooli
mr nooliOP2y ago
If anyone else runs into this issue, check out this comment, I've run into another issue so need to confirm if it works, but nonetheless: https://discord.com/channels/595317990191398933/846453104382836766/1219244879868334080 (CF's discord)

Did you find this page helpful?