node.js / Express throws 'RangeError: Maximum call stack size exceeded' under high load node.js / Express throws 'RangeError: Maximum call stack size exceeded' under high load node.js node.js

node.js / Express throws 'RangeError: Maximum call stack size exceeded' under high load


I have faced same problem in one of my production environment. During the analysis, I found following things, may be i am wrong. But I hope, this will help you...

This problem is basically associated with Socket. There is a option how many open Socket connection should accept? and can the connection keep in half open?.

Normally this kind of exceptions happen only because of how frequent you hit server in particular time period.

Let me explain clearly...

  1. Let assume there is only two socket path and you have four request each should take 5 seconds of processing time.

  2. In general NodeJs can serve perfectly when you give 2 request in 0th second and remaining 2 in 6th second.

  3. Rather than like this, if you give 4 request in 0th second, then NodeJs ready to serve 2 request only. NodeJs is simply close socket for remaining two request.Note: Later if you give the same request, NodeJs will accept and give the response.

  4. For more information, please go through socket.io.js implementation.

And my solution is,

  1. Create load balancer in server friendly way.
  2. Run the NodeJs instances or clusters under the load balancer.

Or If you find any other easy way to solve this, Please update this post...

I am waiting to know a great solution for this problem.

Thanks


I thought I would update my own post to explain what the fix was for me.

After realizing that I had done everything else I knew how to do, the solution presented itself by doing this:

Install Express version 3

There were so many differences and changes that needed to be made to the core code that it took me a full day just to do the conversion. However, in doing so, I was able to take advantage of many new v3 featuers including the .param method for attaching helpers to your :param variables in each route. This eliminated several of my old "helper" functions, so instead of chaining through the routes, I used that instead.

I now have a full understanding of routes/middleware, and simply by re-writing for Express v3, my problem went away!

Since this isn't an exact answer, these are the things I used to learn how to make the conversion:

Express v3 API reference

Information on how routes work

Awesome HOWTO doc! Thanks to those guys!