P
Prismaβ€’6mo ago
AmazingViegas

Prisma hanging on cloudflare

Hello! I am using Prisma ORM on cloudflare workers and I am seeing quite a strange error:
The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response.
The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response.
Is this some known prisma issue on cloudflare edge runtime? Never happened before in Verce serverless afaik. Any help would be useful, thank you so much in advance. πŸ˜„ This is my worker code:
export const getChat = createServerFn()
.middleware([authenticatedMiddleware])
.validator(z.string())
.handler(async ({ data, context }) => {
const chat = await database.chat.findUnique({
where: {
id: data,
},
include: {
messages: {
orderBy: {
createdAt: "asc",
},
},
},
});
if (!chat) {
throw Error(`Chat with id ${data} not found`);
}
if (chat.userId !== context.userId) {
throw Error("Unauthorized access to chat");
}
return chat;
});
export const getChat = createServerFn()
.middleware([authenticatedMiddleware])
.validator(z.string())
.handler(async ({ data, context }) => {
const chat = await database.chat.findUnique({
where: {
id: data,
},
include: {
messages: {
orderBy: {
createdAt: "asc",
},
},
},
});
if (!chat) {
throw Error(`Chat with id ${data} not found`);
}
if (chat.userId !== context.userId) {
throw Error("Unauthorized access to chat");
}
return chat;
});
9 Replies
Prisma AI Help
Prisma AI Helpβ€’6mo ago
You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.
Nurul
Nurulβ€’6mo ago
Hey! I haven't ran or encountered this error before. Is this happening on latest prisma version?
Nurul
Nurulβ€’6mo ago
Deploy to Cloudflare Workers & Pages | Prisma Documentation
Learn the things you need to know in order to deploy an app that uses Prisma Client for talking to a database to a Cloudflare Worker or to Cloudflare Pages.
Orbviox
Orbvioxβ€’4mo ago
Followed every instruction on the internet I've found in the last 9 days. I cannot get database connected from Prisma to CF Workers @Nurul apologies for the ping. I can now provide with a repro: https://github.com/ineshbose/nitro-prisma-cloudflare-issue
Orbviox
Orbvioxβ€’4mo ago
GitHub
Module Path Resolution Error When Using Monorepo + Nitro + Prisma ...
Environment Linux x64, NodeJS v22.15.0 Reproduction I've created a minimal reproduction repo using pnpm monorepo + Nitro + Prisma, which reliably reproduces the bug on my machine (Linux x64, No...
Nurul
Nurulβ€’3mo ago
Btw this is fixed in prisma version 6.15.0
Orbviox
Orbvioxβ€’3mo ago
yes - thanks! caught that πŸ™‚ just that dev environment is broken due to Rollup misconfiguring path to the wasm compiler
blackfish
blackfishβ€’3mo ago
Hi, I'm encountering the same issue with Prisma (v6.16.2) when connecting to a PostgreSQL database (AWS Aurora) via Hyperdrive in Cloudflare Workers. The Worker often hangs or throws errors during database connection, particularly during the initial request. Setup Details: Prisma Version: 6.16.2 (@prisma/client, @prisma/adapter-pg) Environment: Cloudflare Workers with Hyperdrive Database: AWS Aurora PostgreSQL Wrangler: Latest, with compatibility_flags = ["nodejs_compat"] in wrangler.toml schema.prisma:
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
previewFeatures = ["driverAdapters", "views"]
runtime = "workerd"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

...schemas...
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
previewFeatures = ["driverAdapters", "views"]
runtime = "workerd"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

...schemas...
Prisma Client Instantiation:
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '../../generated/prisma/client';
import type { CFEnv } from '../../types';

let prisma: PrismaClient | undefined;

export function getPrismaClient(env: CFEnv): PrismaClient {
if (!prisma) {
const adapter = new PrismaPg({
connectionString: env.HYPERDRIVE.connectionString,
});

prisma = new PrismaClient({
adapter,
log: ['error', 'warn'],
});
}
return prisma;
}
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '../../generated/prisma/client';
import type { CFEnv } from '../../types';

let prisma: PrismaClient | undefined;

export function getPrismaClient(env: CFEnv): PrismaClient {
if (!prisma) {
const adapter = new PrismaPg({
connectionString: env.HYPERDRIVE.connectionString,
});

prisma = new PrismaClient({
adapter,
log: ['error', 'warn'],
});
}
return prisma;
}
The Worker frequently hangs (error: "Workers runtime canceled this request because it detected that your Worker's code had hung") during the first DB interaction in my worker. This happens inconsistently, during high load. Previously, I had maxUses: 1 in the PrismaPg config, which caused hangs; removing it to use default led to more frequent errors like stale connections.
Orbviox
Orbvioxβ€’2mo ago
don’t cache the prisma client in CF - I learnt

Did you find this page helpful?