Steverino
Steverino

Reputation: 2266

Prevent Node.js timing out on long DB requests

I'm running a Node.js server with Express.js and the 'mysql' package to make DB calls. This server makes requests to a MySQL database on an external machine. These requests involve large joins being executed, and take a long time, which I expect. Unfortunately, Node is impatient and even though for my purposes it's okay for these DB calls to take a long time, Node is returning a time-out error state on the DB call instead of waiting patiently for the data to come back. Is this configurable? How can I make Node wait patiently? Note, I know MySQL is returning queries correctly because an Apache/PHP server making the same query receives the correct response from MySQL without timing out.

Upvotes: 1

Views: 640

Answers (1)

Kable
Kable

Reputation: 1045

You can use the optional timeout option when you make a query

connection.query({sql: sqlString, timeout: 60000}, function () { ... });

Reference

Upvotes: 3

Related Questions