Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js crashing

Node.js crashing

Problem

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  /logs/stderr.log 
Problem courtesy of: Tom Krones

Solution

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();
});
Solution courtesy of: Pascal Belloncle

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js crashing

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×