-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MaxListenersExceededWarning with adapter-pg #28037
Description
Bug description
When executing enough transactions in quick succession and pg-pool starts to reuse clients, error handlers are re-attached to them but old ones aren't removed.
prisma/packages/adapter-pg/src/pg.ts
Lines 197 to 198 in ec64269
| const conn = await this.client.connect().catch((error) => this.onError(error)) | |
| conn.on('error', (err) => { |
I originally thought it's pg-pool's fault, but doesn't seem to be the case: brianc/node-postgres#3539
Severity
🔹 Minor: Unexpected behavior, but does not block development
Reproduction
Run any transaction in a loop without any batching mechanism, e.g.
for (const item of array) {
await prisma.model.upsert({ ... });
}Expected vs. Actual Behavior
I would expect not to see a warning in the console :D
MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 error listeners added to [Client]. MaxListeners is undefined. Use events.setMaxListeners() to increase limit
Frequency
Consistently reproducible
Does this occur in development or production?
Only in production (e.g., query engine, generated client)
Is this a regression?
Possibly: f601e6f#diff-8d8247806f3cca322d2f0eaeedfcd626e1c518f2409d0dc092663e38f54b6966R171
Workaround
Removing the events limit
import events from "node:events";
events.setMaxListeners(Infinity)Prisma Schema & Queries
Irrelevant
Prisma Config
No response
Logs & Debug Info
Environment & Setup
Probably irrelevant?
Prisma Version
prisma : 6.15.0
@prisma/client : 6.15.0
Computed binaryTarget : debian-openssl-3.0.x
Operating System : linux
Architecture : x64
Node.js : v22.18.0
TypeScript : 5.9.2
Query Engine (Node-API) : libquery-engine 85179d7826409ee107a6ba334b5e305ae3fba9fb (at node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
PSL : @prisma/prisma-schema-wasm 6.15.0-5.85179d7826409ee107a6ba334b5e305ae3fba9fb
Schema Engine : schema-engine-cli 85179d7826409ee107a6ba334b5e305ae3fba9fb (at node_modules/@prisma/engines/schema-engine-debian-openssl-3.0.x)
Default Engines Hash : 85179d7826409ee107a6ba334b5e305ae3fba9fb
Studio : 0.511.0