#database connections breaking once adding middleware causing edge runtime to trigger

1 messages · Page 1 of 1 (latest)

prisma craneBOT
#

Hi @prime fractal. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

prime fractal
#

good

prisma craneBOT
#

It seems like you're experiencing issues with database connections when adding middleware to your Next.js application. This could be related to the Edge runtime environment, which has certain limitations.

Edge Middleware has a CPU limit of 50ms on average, which refers to the actual net CPU time, not the execution time. For example, when you are blocked from talking to the network, the time spent waiting for a response does not count toward CPU time limitations (source (https://vercel.com/docs/functions/runtimes#edge-middleware-cpu-limit)).

Additionally, Edge Middleware can only use up to 128MB of memory. If it exceeds this limit, the execution will be aborted and a 502 error will be returned (source (https://vercel.com/docs/functions/edge-middleware/limitations#memory)).

If your Edge Middleware depends on a database far away from one of Vercel's Edge regions, the overall latency of API requests could be slower than expected. To avoid this issue, use a global database. Vercel has multiple global storage products, including Edge Config, Vercel KV, and Vercel Blob (source (https://vercel.com/docs/functions/edge-middleware#using-a-database-with-edge-middleware)).

There's also a reported issue on GitHub where a user experienced a similar problem when migrating from Next v14.1.4 to v14.2.1, using @prisma/client v5.12.1. The generated code contained 'async/await' because the module was using "topLevelAwait". However, the target environment did not appear to support 'async/await', which caused runtime errors (source (https://github.com/vercel/next.js/issues/64792)).

#

Please ensure that your middleware and database setup aligns with these constraints and requirements. If the issue persists, it might be helpful to provide more specific details about the middleware you're adding and the errors you're encountering.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@prime fractal kapa.ai is still learning and improving, please let us know how it did by reacting below