Repository navigation
Description
Bug description
findMany throws an unhandled RangeError: Maximum call stack size exceeded from @prisma/client-engine-runtime's query interpreter once a query
processes roughly 59,000–60,000 items in one go. Reproduced with two independent, minimal query shapes that don't share any obvious code path
except "many items processed in one query":
- A
findManywhose select includes a to-many relation that actually has matching child rows for enough parent rows. - A
findManywith a singlein: [...]filter containing more than ~59-60K values, with no relations selected at all.
Both fail at the same threshold, which suggests a shared recursive routine rather than two separate bugs. Below the threshold both queries succeed
and return correct data. This is not specific to cursor-based pagination — it reproduces with plain take/orderBy, no cursor/skip involved.
Severity
🚨 Critical: Data loss, app crash, security issue
Reproduction
No public repository yet — happy to put one together if useful, but the repro is small enough to include in full here (single schema, two models,
no app-specific dependencies).
Schema:
model Group {
id Int @id @default(autoincrement())
members GroupMember[]
}
model GroupMember {
id Int @id @default(autoincrement())
groupId Int
userId Int
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
}
Seed: 100,000 Group rows, each with exactly 4 GroupMember rows (400,000 total).
Case 1 — nested to-many relation:
const adapter = new PrismaPg({ connectionString: DATABASE_URL });
const prisma = new PrismaClient({ adapter });
// works
await prisma.group.findMany({
select: { id: true, members: { select: { userId: true } } },
take: 59000,
orderBy: { id: 'asc' },
});
// throws
await prisma.group.findMany({
select: { id: true, members: { select: { userId: true } } },
take: 60000,
orderBy: { id: 'asc' },
});Binary-searched the exact boundary: fails starting at take: 60000, consistently succeeds at take: 59000 (4 children per parent, ~236K total rows attached across the batch). The same shape one relation deeper reproduces it too, at a similar order of magnitude (fails at take: 80000, succeeds at take: 50000).
Case 2 — flat in filter, no relations at all:
// works
await prisma.groupMember.findMany({
where: { groupId: { in: Array.from({ length: 59000 }, (_, i) => i + 1) } },
select: { groupId: true, userId: true },
});
// throws
await prisma.groupMember.findMany({
where: { groupId: { in: Array.from({ length: 60000 }, (_, i) => i + 1) } },
select: { groupId: true, userId: true, turnOrder: true },
});Fails at 60,000 values in the in array, succeeds at 59,000. No relation selected at all in this query.
Ruled out as necessary: _count in the select, cursor pagination (cursor/skip), multi-level relation nesting.
Ruled out as sufficient: a nested to-many relation with zero matching children never crashes, even at take: 100000 — the recursion scales with rows actually attached, not just parent rows returned.
Expected vs. Actual Behavior
Expected: a query returning 60K+ rows should succeed the same way it does at 59K — or if there's an intentional limit, surface as a typed Prisma
error, not an unhandled stack overflow.
Actual:
RangeError: Maximum call stack size exceeded
at e.interpretNode (/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:196:26)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at async /node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:246:28
at async Promise.all (index 0)
at async e.interpretNode (/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:243:26)
at async /node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:246:28
at async Promise.all (index 0)
at async e.interpretNode (/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:243:26)
at async e.interpretNode (/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:272:41)
at async e.run (/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:94:23) {
clientVersion: '7.9.0'
}
Frequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
Yes, confirmed. Ran the identical query, against the identical seeded data (same Postgres database, untouched), on the same machine/Node version, against Prisma 6.19.3 instead of 7.9.0:
- Prisma 6.19.3, library engine (@prisma/client, default prisma-client-js generator, no adapter): take: 60000 → OK (994ms), take: 100000 → OK
(1599ms) - Prisma 6.19.3, binary engine (engineType = "binary"): take: 60000 → OK (1143ms), take: 100000 → OK (1792ms)
- Prisma 7.9.0, client-engine-runtime + @prisma/adapter-pg: take: 60000 → RangeError: Maximum call stack size exceeded
Both Prisma 6 engine variants (library and binary — the two Rust-engine code paths) handle 100,000 rows with the nested relation without any issue.
Only the new Prisma 7 TypeScript interpreter fails, and it fails consistently above ~59-60K. This is specific to the new engine introduced in 7.x,
not present in 6.19.3.
Workaround
Yes: keep every findMany under ~59,000 items total (parent rows with attached relation data, or values in a single in filter). We chunk large in filters to 32,000, and fetch to-many relations via a separate, chunked query instead of nesting them in a large-batch findMany, merging in application code. No way found to exceed the threshold in a single query safely.
Prisma Schema & Queries
see Reproduction section
Prisma Config
import { defineConfig } from 'prisma/config';
import * as dotenv from 'dotenv';
dotenv.config();
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: { path: 'prisma/migrations' },
datasource: { url: process.env.DIRECT_URL },
});
// Client instantiation:
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from './generated/client/client';
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
const prisma = new PrismaClient({ adapter });Logs & Debug Info
Not yet captured with DEBUG=* — the failure is a synchronous JS stack overflow inside the interpreter rather than a query/connection-level failure, so debug/DB logs aren't expected to add anything beyond the query being issued; can capture if useful.
Environment & Setup
- OS: macOS (Darwin, arm64) — local repro; production target is Debian (node:20-bookworm-slim), not expected to be OS-specific
- Database: PostgreSQL 15.17 (Alpine, linux/aarch64)
- Node.js version: v22.22.0
Prisma Version
prisma : 7.9.0
@prisma/client : 7.9.0
Operating System : darwin
Architecture : arm64
Node.js : v22.22.0
TypeScript : 5.9.3
Query Compiler : enabled
PSL : @prisma/prisma-schema-wasm 7.9.0-1.e922089b7d7502aff4249d5da3420f6fa55fc6ad
Schema Engine : schema-engine-cli e922089b7d7502aff4249d5da3420f6fa55fc6ad
Default Engines Hash : e922089b7d7502aff4249d5da3420f6fa55fc6ad
Studio : 0.33.0
(@prisma/adapter-pg: 7.9.0, pg: 8.22.0 — not in this output, adding since the driver adapter is central to the repro)
Activity
Hprogram commentedon Jul 22, 2026
I dug into this and can confirm your suspicion of a shared routine is exactly right — both repro shapes converge on a single call site, though the mechanism turns out to be stack-based argument spreading rather than recursion.
Root cause. In
@prisma/client-engine-runtime,renderTemplateSql()appends every SQL parameter behind anIN (...)clause by spreading the whole array as call arguments:For
parameterTuplefragments,flattenedFragmentParamsyields every element of thein:list (case 2) or the parent-key list behind a relation-loading subquery'sWHERE fk IN (...)(case 1) — so a ~60K-item query passes ~60K arguments to a single.push()call, exceeding V8's argument/stack limit.Why chunking doesn't cover it.
chunkParamsis the intended mitigation, but relation-loading subqueries are compiled withchunkable: false, sorenderQueryskips chunking entirely and the full array reaches the spread. And when chunking does run, the per-chunk row merge uses the same pattern —results.rows.push(...result.rows)inquery-interpreter.ts— which can still overflow on high-fanout relations (chunk size × fanout rows).Why the threshold sits at ~59-60K. The limit depends on stack already consumed when the query runs: a bare
push(...arr)only fails above ~125K elements, but with a few thousand frames of app/test-runner/async machinery it fails right around 60K — consistent with your binary-searched boundary and its variation at deeper nesting.I reproduced this deterministically without a database by feeding
renderQuerya synthetic 60K-elementparameterTuplefragment (chunkable: false), and a repo-wide sweep shows these are the only two data-scaled spread sites.The fix is minimal — replacing both spreads with loop-based appends, no behavior change. Opening a PR with regression tests shortly.
fix(client-engine-runtime): avoid spreading row/param-sized arrays on…
fix(client-engine-runtime): avoid spreading row/param-sized arrays on…
fix(client-engine-runtime): avoid spreading row/param-sized arrays on…