'Next js creates different mysql connection pools if behind nginx
this is my first question, hope I do it right!
I'm actually working on a Centos server with nginx as reverse proxy and a NextJs web application.
Until now I've made a single connection for every query to my db, but I want to switch to pool connection to my DB (with npm module mysql2), but apparently there's something I'm missing...
If I run my application local, or on the server without nginx, with yarn start, it opens just one pool (I can see them by running the query SHOW PROCESSLIST on the DB in use). But in the moment I add nginx as reverse proxy, every request my app receives opens a pool and the latter never gets closed or called again (apart from the one pool opened if someone visits the page for which I use the nextjs function router.push(/url)).
It happens also if I run yarn dev: it opens a connection pool for every new page next has to build in development or if I make some changes to pages and save. But this behaviour I understand.
The nginx configuration is a normal configuration, and everything works fine.
I've surfed the web far and wide, but didn't find anything that could help me understand what could be going on between nginx-next-mysqldb, and no one reported any problem whatsoever. Is this how it's supposed to be or there's something that I should do to make it work?
Solution 1:[1]
Oops... my bad... Transitioning from single db connections to pool, I left a function which made a single connection, which I was not closing.
So there's no problem and nothing to uncover behind nginx-next-mysql.
Don't know if anyone will stumble upon this problem, ever, but, just make sure you don't have any single connection to your db... And make sure to close them :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tyzion |
