Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:01:27+00:00 2026-05-26T01:01:27+00:00

as I use Node.js for not too long time yet, I’ve ran into a

  • 0

as I use Node.js for not too long time yet, I’ve ran into a following problem. I understand that using callback-driven paradigma we need to convert loops we used in synchronous code into recursion. My problem is I cannot understand how deep node can go with recursion, results with different tests are inconsistent. For example, I tried code I’ve found on Web:

    var depth = 0;

    (function recurseBaby() {
        // log at every 500 calls
        (++depth % 500) || console.log(depth);

        // bail out ~100K depth in case you're special and don't error out
        if (depth > 100000) return;

        recurseBaby();
    })();

It gives me node exception (max recursion depth) after 18500 recursions.
So I tried to add some functionality, like working with queue:

var depth = 0,
    Memcached = require('memcached'),
    memcacheq = new Memcached('127.0.0.1:22201');


(function recurseBaby() {
    // log at every 500 calls
    (++depth % 500) || console.log(depth);

    // bail out ~10M depth in case you're special and don't error out
    if (depth > 10000000) return;

    memcacheq.set('test_queue', 'recurs' + depth, 0, function (error, response) {
        return recurseBaby();
    });
})();

It didn’t finish yet, but works so far for more than 4 million recursions (and queue is actually getting filled). So I would like to clarify, how recursion depth limit works in node. My guess would be that if I do something in that recursively called function, node has more time to free call stack, but I may be terribly wrong. Any clarifications from more experienced node users are welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:01:27+00:00Added an answer on May 26, 2026 at 1:01 am

    There is no recursion in your second example at all.

    In the first example you clearly have a recursive call.

    In the second example a call is made to memcacheq.set which returns immediately, and then your function returns. It will have made a node somewhere of the function to call when the triggered event happens at some later time.

    — No recursive call has been made —

    At some point in time later the memcache function will finish and queue an event to the event queue to trigger your callback.

    But note that this is done from an event in the event queue, NOT by a direct recursive call from your function which has probably long since returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not too familiar with ExtJS, but am working on a project that uses
How can I use XPath to select an XML-node based on its content? If
I want to use LabVIEW's Call Library Function Node to access a DLL function,
I need to insert the comment form directly to the node template (I use
Helo! Is this possible to use string value of one node which tells what
I am trying to parse a C-function like tree expressions like the following (using
node.js provides lower layer V8 options too. These options are very low layer like
I'm running a simple web app backed by node.js, and I'm trying to use
I'm maintaining some code that has far too many document.write instances. For example, the
Is it possible to use XPath to select only the nodes that have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.