Node.js crashing
My node.js app keeps crashing. It is a simple web service that gets data from a mysql database. I receive between 20 and 30 thousand requests per day. I'm not sure if it crashes because I need to give it more resources or if I have a problem with my code. It was hosted on AppFog and here is the crashlog.
I'm not sure what the hashish package is, but I tried to install it using "npm install hashish" and that 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)
source to share
How do you get your connection? Do you get it once, or do you get a new one for each request and then return it to the pool? The pool should handle stale connections behind the scenes.
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();
});
source to share
You will probably have to handle the socket error event ( http://nodejs.org/api/net.html#net_event_error_1 ) for all your connections.
This will prevent it from crashing and you should see the actual problem.
source to share