stack overflow

Dec 10, 2012 at 6:12 PM

he following code (based upon a scheme that has been running for about a year) is currently successful. However, upon completion(?), it generates a "stack overflow line: 0" error.

1. document.ready() examines a library, and sets a control button if the condition is realized.
2. The button sets off processRecord, which does the same thing but with a sort-by-date clause.
3. Then, it iterates through all candidate items, opening the (email) file and extracting its content. Certain items in that content are to be entered in a list.
4. doStuff processes that content data, and with findExisting checks to see whether the item is already in the list.

If findExisting is disabled, there is no stack overflow error.

If findExisting is enabled, processing results are as intended but a stack overflow error is generated.

<script language="javascript" type="text/javascript"> 

	var devGFSSEForms = function() {
...
		//as it stands, this first routine runs whenever the page is accessed
		$(document).ready(function() {  
...
			$().SPServices({
				operation:  "GetListItems",  
				listName: "{D3795486-9926-424E-8F14-59BE5DB65BA8}",	//dev GFSSEForm
				CAMLViewFields: "<ViewFields><FieldRef Name='LinkFilename'/><FieldRef Name='Exported' /></ViewFields>", 
				completefunc: function (xData, Status) { 
...
				}  //completefunc
			});  //SPServices
		});  //document.ready

	return {

		processRecord: function () {
			var myQueryOptions = "<QueryOptions />";
			var myQuery = "<Query><OrderBy><FieldRef Name='Created_x0020_Date' /></OrderBy><Where><Eq><FieldRef Name='Exported' /><Value Type='Integer'>0</Value></Eq></Where></Query>";	//user, action but no attention to Orphan status
			$().SPServices({
				operation:  "GetListItems",
				listName: "{D3795486-9926-424E-8F14-59BE5DB65BA8}",	//development
				CAMLViewFields: "<ViewFields><FieldRef Name='LinkFilename'/><FieldRef Name='Exported' /></ViewFields>", 
				CAMLQuery: myQuery,
				CAMLQueryOptions: myQueryOptions,
				completefunc: function (xData, Status) {
					$(xData.responseXML).SPFilterNode('z:row').each(function() {
...
					});  //each()
					$.each(arIDs, function(index, value) {
						var promise = $.ajax({
							type:"GET",
							url:"GFSSEForm/" + arIDs[index][2],
							dataType:"text"
						});
						promise.done(doStuff);	//magically passes the data along, too
						promise.fail(function() {alert("failed to open this eform: " + arIDs[index][2]);});
					});  //each
				}  //completefunc
			});  //SPServices
		}  // processRecord()
	};	// public method processRecord() [return]
			
		function doStuff(data) {
...
				var useThis = arValues;
				if(arValues[0] != "") {
					var strName = arValues[0];
					var strAction = arValues[5].substring(0,1);
					findExisting(strName, strAction);	// calls SPServices
				}	// if username wasn't empty
				arValues = useThis;	//this works
...
					writeNew();
...
		}  // doStuff()

		function writeNew() {
...
			arValues = strUseThis.split(",");
			for(i=0; i<iFields; i++) {
				strTest = arValues[i];
				if(strTest.length > 255) strTest = strTest.substring(0,255);
				strField = arFields[i]; 
				vpairs.push([strField,strTest]);
			}
			$().SPServices({
				operation: "UpdateListItems",
				batchCmd: "New",
				listName: "{37229D49-3F6D-4812-A2F0-A0DC55B89DD1}",  //development list
				valuepairs: vpairs,
				completefunc: function(xData, Status) {
...
				}	//completefunc
			}); //SPServices

		}  // writeNew()

...
		function findExisting(user, action) {
			var queryOptions = "<QueryOptions />";
			var query = "<Query><Where><And><And><Eq><FieldRef Name='Title' /><Value Type='Text'>" + user + "</Value></Eq><BeginsWith><FieldRef Name='col05x' /><Value Type='Text'>" + action + "</Value></BeginsWith></And><Neq><FieldRef Name='Orphan' /><Value Type='Integer'>1</Value></Neq></And></Where></Query>";  
			//CAML looks for existing items having same name and action, ignoring any that have already been marked as orphans
			$().SPServices({
				operation:  "GetListItems",
	      async: false,		//required!!!!! ; not used: no stack overflow, runs Orphan; use: stack overflow, no Orphan
				listName: "{37229D49-3F6D-4812-A2F0-A0DC55B89DD1}",	//development GFSSVerified list
				CAMLViewFields: "<ViewFields><FieldRef Name='Title'/><FieldRef Name='col05x' /></ViewFields>", 
				CAMLQuery: query,
				CAMLQueryOptions: queryOptions,
				completefunc: function (xData, Status) {
					var iCount = parseInt($(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount"));
					if(iCount > 0) {...}
...  //in the current data set I'm using, there is never a reason to come here
				}  //completefunc
			});  //SPServices
		}

...
  }(); //devGFSSEForms

</script>  

Coordinator
Dec 10, 2012 at 7:33 PM

Michael:

Where are you seeing the stack overflow message? In the browser window or in the debugger (e.g., IE's Developer Tools)? Have you tried stepping through your code?

M.

Coordinator
Dec 10, 2012 at 7:34 PM

p.s. You probably need async: false in all of your SPServices calls.

M.

Dec 10, 2012 at 11:39 PM

Thanks. We're a government installation, so are at MOSS with IE7--no debugging possible. I'll first try the async: false trick, then try the code on an SP2010 machine and IE9 (not used in-house but would help understand whether the problem is IE).

The "stack overflow..." message is an information dialog that is system-generated. Appears after the writes to the list, so far as I can tell.

 

Coordinator
Dec 11, 2012 at 4:53 PM

Still not clear where the error is occurring. Is it an error from SharePoint or from the browser?

In IE7, you can use the Internet Explorer Developer Toolbar, assuming you're able to install it.

M.

Dec 11, 2012 at 5:49 PM

I think it's clearer now, and I think you're right to wonder whence originates the stack overflow message. My guess is that it is the browser. Over the past few days, when I have had many dialogs come up in the debugging process, I got used to seeing a stack overflow message, and I just automatically assumed that was because the instance of IE7 could not handle all those dialogs (almost certainly, given our environment, due to lack of RAM). 

Now, I have just put everything on to a MOSS virtual machine that runs under sufficient RAM (and, admittedly, with IE8), and have run the same code against the same data samples, and there was no error message.

So, let's presume--until proven wrong--that the error is due to limitations of the browser.

By the way, also putting this application on SP2010 showed clearly that another of the SPServices instances needs async:false. So, that makes three. The rest did not generate any problems with the default value.

Your instincts have prevailed, and the browser appears to be the culprit here.

Thanks for the help...

Michael

Coordinator
Dec 11, 2012 at 5:58 PM

I'll be interested to hear what you figure out and if you get it working. Sounds like progress, at least.

M.

Dec 12, 2012 at 1:40 PM

Boy, this was interesting. I searched Bing for: [Internet Explorer 7 "stack overflow"], and found a lot of hits. One in particular caught my attention: "recursion that passes through the host global object is limited to a stack depth of 13" [I didn't note the URL but searching for that string should find it in Stack Overflow].

After many experiments, I found that if I enclose the SPServices call that occurs within the writeNew function (above) with:
if(iGlobal < 13) {  ...}
then all is well. If I increase the limiter to, say, 15, the application (not the iteration) ends with a "stack overflow" message.
Trying to understand his next sentence, I removed the Crockford module pattern I use with most of the SharePoint JavaScript code, but it made no difference.

Michael

Coordinator
Dec 12, 2012 at 6:54 PM

It's really hard to debug stuff like this from afar. I don't see anything obviously wrong with what you're doing. I'd suggest stepping through it in a debugger to see if you're nesting recursively or something.

M.