My node.js app keeps crashing. It's a simple web service that gets data from a mysql database. I get about 20k to 30k queries a day. I'm not sure if it's crashing because I need to give it more resources or if I have a problem with my code. It's hosted in AppFog and here's the crashlog.
I'm not sure what the hashish package is but I tried installing it using 'npm install hashish' and it didn't fix the problem.
Any thoughts?
C:\Users\Tom\\nodejs>af crashlogs TomsApp
====> /logs/staging.log <====
# Logfile created on 2013-02-05 00:53:01 +0000 by logger.rb/25413
Installing dependencies. Node version 0.8.14
Installing mysql@mysql@0.9.6 from local path
Installing hashish@hashish@0.0.4 from registry
Package is not found in npm registry hashish@hashish@0.0.4
Failed getting the requested package: hashish@hashish@0.0.4
Installing require-all@require-all@0.0.5 from local path
====> /logs/stderr.log <====
events.js:71
throw arguments[1]; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (/mnt/var/vcap.local/dea/apps/ta-0-365d7313671d4e40105a4d158
f1247d5/app/node_modules/mysql/lib/protocol/Protocol.js:63:13)
at Socket.onend (stream.js:66:10)
at Socket.EventEmitter.emit (events.js:126:20)
at TCP.onread (net.js:417:51)
You probably have to handle the error event on the socket (http://nodejs.org/api/net.html#net_event_error_1) for all your connections.
That will keep it from crashing and you should then see the actual problem.
I would say mysql server's refusing the connection maybe you want to look into that
How are you getting your connection? Do you get it once, or get a new one for each request and then return it to the pool? The pool should be handling stale connections behind the scene.
var mysql = require('mysql');
var pool = mysql.createPool({
host : 'example.org',
user : 'bob',
password : 'secret'
});
// for each request where you need the database connection, wrap it with
pool.getConnection(function(err, connection) {
// do something with connection here
...
connection.end();
});