For testing purposes, I've set up this little script:
Client = require('mysql').Client, client = new Client();
client.user = 'root'; client.password = 'root'; client.port = 8889;
counter = 0; data = '';
setInterval(update, 10);
function update(){
counter++; request();
}
var sys = require('sys'), fs = require('fs'), http = require('http'),
url = require('url'),port = 8001;
http.createServer(function(request, response) {
response.writeHead(200, {
'Content-Type': 'text/html'
}); response.end('Hello world');
}).listen(port);
function request(){
client.connect();
client.query('USE db');
client.query(
'SELECT * FROM table', function selectCb(err, results, fields) {
if (err) { throw err; }
if(results.length > 0)
{
var firstResult = results[0];
data = firstResult['data'];
}
client.end();
}
);
}
It works fine, but, after an hour or so, the server crashes and outputs the following error:
node.js:180
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: EADDRINUSE, Address already in use
UPDATE
I updated the code. It now includes some mysql. This definitely is causing the problem, although I don't know exactly why. Leaving this part out stabilizes the loop. Also, I updated the time interval to every 10 ms. (The server crashes after a few minutes with the mysql part in it, but keeps on running without)
15382without that error so far, so it might be worth a try.