Database Connection Pool Exhaustion During Vercel Build

Summary

Plasmic codegen builds are failing on Vercel due to database connection pool exhaustion when pre-rendering pages with data sources.

Environment

  • Plasmic Setup: Codegen mode
  • Deployment Platform: Vercel

Issue Description

During the Vercel build process, when Plasmic attempts to pre-render pages that fetch data from our database, the build fails with 31 connection pool errors. It appears that multiple parallel pre-rendering processes are exhausting the available database connections.

Error Messages

1. "remaining connection slots are reserved for non-replication superuser connections"
2. "sorry, too many clients already"  
3. TypeError: Cannot read properties of undefined (reading '0')
   - This appears to be a secondary error caused by failed data fetching

Full Error Stack

Error: {"error":{"statusCode":400,"__plasmicIgnoreError":true,"message":"remaining connection slots are reserved for non-replication superuser connections"}}
at /vercel/path0/node_modules/@plasmicapp/data-sources/dist/index.js:334:13
at Generator.next (<anonymous>)
at fulfilled (/vercel/path0/node_modules/@plasmicapp/data-sources/dist/index.js:50:24)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Expected Behavior

  • Plasmic should manage database connections efficiently during pre-rendering
  • Connection pooling should be properly configured to handle parallel page generation
  • Connections should be reused or properly closed after use

Actual Behavior

  • Database connection limit is reached during build
  • Multiple “PLASMIC: Encountered error when pre-rendering” messages
  • Build fails with connection exhaustion errors

Hi @higinio_maycotte, the database in question is on your side right? We can’t adjust how this works from our end since Next.js is making a separate request for each page that’s being built. However, I can think of a few ways you can handle this:

  1. Increase your database’s connection limit.
  2. Add an API server in front of your database to manage connections.
  3. Not sure if it’s possible, but maybe Next.js has a way to limit parallelism of builds, such that only a few pages get built at once?

@jason thanks for the quick reply.

I had assumed these connection errors were coming from Plasmic’s data fetching service, not our Supabase DB directly. We’re using a large Supabase database mapped through Plasmic Studio, and I understood all data flows through the Plasmic proxy during builds.

If the errors are actually from our Supabase hitting connection limits, is there a way to configure connection pooling on the Plasmic side? Or would it be better to switch to fetching from our API instead of using the database + Plasmic proxy approach?

I was already planning to build custom data components for API fetching - this might accelerate that timeline.

Thanks as always.

Hi @higinio_maycotte, we do not plan to implement connection pooling.