Hello,
I am using serverless-mysql in a Next.js environment and during development I found out that on hot reload the open connections were lost, causing the MySQL Error “Too many connections”.
This is the way I fixed it, following this issue: https://github.com/vercel/next.js/issues/7811
The mySqlClient is stored as a global variable, so it is not instantiated on every Next.js hot reload.
I'd like to know what you think about this solution and if can be improved (for instance calling mySqlClient.quit() if the client is already a global variable)
As you said, you could use mySqlClient.quit to make sure the connection is properly cleaned up but re-use is preferable than re-instantiating a new connection imo.
Hello, I am using serverless-mysql in a Next.js environment and during development I found out that on hot reload the open connections were lost, causing the MySQL Error “Too many connections”.
This is the way I fixed it, following this issue: https://github.com/vercel/next.js/issues/7811 The mySqlClient is stored as a global variable, so it is not instantiated on every Next.js hot reload.
I'd like to know what you think about this solution and if can be improved (for instance calling mySqlClient.quit() if the client is already a global variable)