简体   繁体   中英

node-mysql connectTimeout

I'm using Nodejs to write a socket server for my app (using Corona SDK), and so far so good, and I'm using node-mysql ( page for node-mysql ), and that works too, but... if nothing happens and nothing uses the connection to the db, after 2 minutes (which is the default timeout) the connection closes, while I need it to remain always open as long as the scrip process is still running, can I simply set the timeout attribute of the connection to 0, and that will keep it always open, or do I need to set it for a really long time, like 24 hours (in millisecond) in order to keep it up at all times (I'm putting 24 hours since our server restarts once a day anyway).

Thanks!

Well, it would seem the problem was the mysql server wait_timout, which was set to 300 seconds (5 minutes), and it was what disconnected my script. seeing as I don't really want to change that variable since not only my script uses that DB, for the time being I'm simply executing a light query with a setInterval every 4 minutes, hoping this will keep my connection alive.

If you want to keep your MySQL server always running, you have to set the connectTimeout option to 0 . See the the commit "Default connectTimeout to 2 minutes" . 0 was the default option before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM