I have several cron jobs running and the task that cron has to do is execute a file that in turn checks and compares crawled data with data in the database, if it exists then the script ends and if it does not exist it inserts the data to be used by another cron task at a later time.
I have MySQL connections set by pooling, this works as expected for front end users as when I watch the process list as I can see users of my application in real time re-use a sleeping connection in MySQL and not create a new one.
The issue I am having with cron jobs is that every time cron runs the same job it creates a new connection to MySQL on a new port and does not look to reuse its last connection for that same task from the pool via the same port even though I use
connection.release();. Is this normal behaviour from cron?.. If it isn't normal then is there a way to force re-using of the same port by the same repeating query?.
The outcome of this is that after 3-4 days I have hit the connection limit and have to restart server to clear this and to begin again. Obviously I would sooner get to the root of the issue without having to resort to rebooting every few days, so any advice or pointers in the right direction would help.
The system is Ubuntu 18.04 and running node processes via cron. (npm MySQL library)