Pergunta

I'm bit new on the Node.js front and for now its awesome. I've encountered a small problem while running node (/w express) locally - Every request after the 10th one hangs and is marked as Pending in the Chrome Inspect Network.

As for modules i'm using less-middleware, express, jade and MySQL and i only do one SQL query (using mysql.createPool). Why is this request still Pending and how can i fix this?

Since i'm new at Node i'm not sure if i've tried everything so any help would be appreciated!

Foi útil?

Solução

It sounds like you're not releasing the MySQL connection you're getting back from the pool. If you don't, the pool will run out of free connections and will start waiting for any to become available (and until then, stall the request).

So your code should look similar to this:

var pool = mysql.createPool(...);
...
// in your request handler:
pool.getConnection(function(err, connection) {
  if (err) ...handle error...;
  connection.query(function(err, results) {
    // release connection
    connection.release();
    // handle results
    ...
    // send back a response
    res.send(...);
  });
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top