Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js crashing

Tags:

node.js

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@[email protected] from local path
Installing hashish@[email protected] from registry
Package is not found in npm registry hashish@[email protected]
Failed getting the requested package: hashish@[email protected]
Installing require-all@[email protected] 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)
like image 222
Dev01 Avatar asked Aug 26 '26 20:08

Dev01


2 Answers

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();
});
like image 96
Pascal Belloncle Avatar answered Aug 29 '26 17:08

Pascal Belloncle


I would say mysql server's refusing the connection maybe you want to look into that

like image 32
srosh Avatar answered Aug 29 '26 15:08

srosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!