Hello John,
If you are under heavy load, could this be a db issue? Like the db engine taking long to return the data, hence queries are getting queued one after the other and finally reach a few hundreds of it?
Or you are right and your Lua script sometimes doesn't release the handler as it just shall... To check this, you could for instance log a debug message before and after doing your db query, and check after a few minutes if you have the equivalent of 'before' and 'after' query messages... If more before than after, then something is happening.
You could do a 'show processlist;' on the MySQL cli too to understand what are exactly the few hundreds of open connections.
Also, is your stored procedure complicated? I'm not DBA but if it's too tricky, you could imagine to move the load on the Lua processing instead of MySQL. I have the same use cases on my environment and I made sure my MySQL queries are dumb as possible and I take the benefit of Lua to process the data returned.
I'm just dropping some ideas that I'm thinking about now. Nothing very precise though (sorry...).
Florent