serverless-mysql
serverless-mysql copied to clipboard
Thread doesn't get cleaned up?
Hi, I've recently started using serverless mysql specially because of my Next.js environment and I was checking around for proper connection management and while logging the event actions, I figured the connection thread ID keeps on increasing every time I refresh my API URL on the browser.
I have the connection created, data fetched then closed the connection with connection.quit() as connection.end() didn't work, as shown below
And the console shows the thread ID like
I tried restarting the server but the thread ID still keeps on increasing.
I don't know if this is an okay behavior but from my knowledge using MySQL with different languages previously, there should only ever be a single thread created and removed as soon as the connection is closed if there aren't multiples of operations to be performed, right? Should I be worried or this is normal?
The library was designed for use with serverless functions that have a single concurrency model, so you should avoid using .quit() on every call in order to freeze and reuse the connection on subsequent invocations wherever possible.
.end() is a clean up method that only terminates connections when necessary. As far as the thread number is concerned, I’m guessing that’s likely an internal node thing.
The library was designed for use with serverless functions that have a single concurrency model, so you should avoid using
.quit()on every call in order to freeze and reuse the connection on subsequent invocations wherever possible.
.end()is a clean up method that only terminates connections when necessary. As far as the thread number is concerned, I’m guessing that’s likely an internal node thing.
Thanks for the response. So it's completely safe and fine to keep the connection alive? I figured even without closing the connection, the thread ID keeps on increasing on each request made to the API. Would there be any memory leak issue or something like this caused?
It’s preferable to keep the connection alive as it saves time when you don’t set up and tear connections down. Memory should be a problem.
It’s preferable to keep the connection alive as it saves time when you don’t set up and tear connections down. Memory should be a problem.
Ok thank you very much. I figured that the thread id increasing is because of the hot reload feature of Next.js. I just felt dumb lol
And sorry for creating an issue for something like this. You can close it.