In a normal usage with API Routes, there is a bug in next-connect that causes a possible memory leak. This is a troubling one because from the outside, there would not be any error (API responses will still be served normally to incoming requests)
Normally, a forever-pending promise does not cause an issue. However, since it makes use of references of request and response, it prevents GC from recycling those in memory, creating memory leaks as requests come in.
In a normal usage with API Routes, there is a bug in
next-connect
that causes a possible memory leak. This is a troubling one because from the outside, there would not be any error (API responses will still be served normally to incoming requests)The promise created by calling
handler(req, res)
(usually by Next.js internally at https://github.com/vercel/next.js/blob/1c1a4de0e2d38090fcf95ef0a6f6790006aaa124/packages/next/server/api-utils.ts#L108) will never be able to resolve, causing the logic from there onward to not be executable.Normally, a forever-pending promise does not cause an issue. However, since it makes use of references of
request
andresponse
, it prevents GC from recycling those in memory, creating memory leaks as requests come in.