<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forex Software — Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
	<link rel="self" href="https://forexsb.com/forum/feed/atom/topic/9469/" />
	<updated>2023-06-16T19:16:04Z</updated>
	<generator>PunBB</generator>
	<id>https://forexsb.com/forum/topic/9469/bug-rangeerror-maximum-call-stack-size-exceeded/</id>
		<entry>
			<title type="html"><![CDATA[Re: Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/75310/#p75310" />
			<content type="html"><![CDATA[<p>You are right.</p><p>Node.js executes only a limited count of recursions <img src="https://forexsb.com/forum/img/smilies/sad.png" width="15" height="15" alt="sad" />.</p><p>I&#039;ll upload an update tomorrow.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2023-06-16T19:16:04Z</updated>
			<id>https://forexsb.com/forum/post/75310/#p75310</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/75264/#p75264" />
			<content type="html"><![CDATA[<p>After re-coding the &quot;addSuffixToJsonFile&quot; function that causes the stack overflow from:</p><div class="codebox"><pre><code>function addSuffixToJsonFile(colPath) {
    if (!existsSync(colPath)) {
        return colPath;
    }

    const match = colPath.match(/\((\d+)\).json$/);
    if (match) {
        const index   = Number(match[1]);
        const newPath = colPath.replace(`(${index})`, `(${index + 1})`);
        return addSuffixToJsonFile(newPath);
    }

    const newPath = colPath.replace(&quot;.json&quot;, &quot;_(1).json&quot;);
    return addSuffixToJsonFile(newPath);
}</code></pre></div><p>to</p><div class="codebox"><pre><code>function addSuffixToJsonFile(colPath) {
    // RegExp that matches the last number before the &quot;.json&quot; extension, with and without the index in parentheses
    var regex = /(?:_(\d+)(?:_\((\d+)\))?)?\.json$/;
    var newPath = colPath;

    // Check if the initial file exists
    if (!existsSync(newPath)) {
        return newPath;
    }

    // Loop until a non-existent file path is found
    while (existsSync(newPath)) {
        // Use the replace function with a callback to generate the new file path
        newPath = newPath.replace(regex, function (_, baseIndex, suffixIndex) {
            // If a suffix index is found, increment it by 1, otherwise set it to 1
            var newIndex = suffixIndex ? parseInt(suffixIndex, 10) + 1 : 1;
            // Return a new file path with the updated index in parentheses and the base index unchanged
            return &#039;_&#039; + baseIndex + &#039;_(&#039; + newIndex + &#039;).json&#039;;
        });
    }

    // Return the non-existent file path
    return newPath;
}</code></pre></div><p>The error has gone away. Reason: The error occurred because the function addSuffixToJsonFile used recursion to find a suitable file name, which caused a stack overflow for large numbers like in my case with 5000+ files in the directory. To fix this issue, I have converted the recursion to a loop, which will avoid the stack overflow issue.</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2023-06-15T06:37:29Z</updated>
			<id>https://forexsb.com/forum/post/75264/#p75264</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/75263/#p75263" />
			<content type="html"><![CDATA[<p>Hi Mr. Popov,</p><p>with EG 2.34 I am regularly getting this error:</p><div class="codebox"><pre><code>                        ..:: Express Generator v2.34 ::..

    Market : Unknown GBPJPY H1
    From   : 1986-12-19 14:00, To: 2017-03-21 00:00, Bars: 189249
    Spread : 12, Swap long: 15, Swap short: -17.2, Commission: 11 USD
    Account: 100000 USD, Leverage: 500, Entry: 1 lots

Generator started...

  - Ascended: 5, Calculated: 15279, Opt: 5, Time: 18:00, Coll: 5
Collection exported: ./collections/Unknown_GBPJPY_H1_2017-03-21_str_5_(5172).json

  - Ascended: 10, Calculated: 30019, Opt: 10, Time: 30:54, Coll: 5
Collection exported: ./collections/Unknown_GBPJPY_H1_2017-03-21_str_5_(5195).json

RangeError: Maximum call stack size exceeded, Time: 51:45, Coll: 5
    at existsSync (node:fs:300:1)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:321:10)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)</code></pre></div><p>I think it happens if there are a lot of collection files in the destination directory already (5000+) and it has to cycle through a loop to find the next free number. This can happen if EG runs for a long time and I hope you can fix it to still be able to handle that amount of files (and much more if its running unattended for weeks).</p><p>Please also see <a href="https://stackoverflow.com/questions/20936486/node-js-maximum-call-stack-size-exceeded">https://stackoverflow.com/questions/209 … e-exceeded</a> (in case it helps anything).</p><p>Thanks for the fix in advance.</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2023-06-15T05:59:16Z</updated>
			<id>https://forexsb.com/forum/post/75263/#p75263</id>
		</entry>
</feed>
