Infinite loop on 500 http response

125 views
Skip to first unread message

Julian Russbach

unread,
Feb 9, 2015, 11:52:54 PM2/9/15
to jst...@googlegroups.com
I started using jstree last month and it has saved me a bunch of time. I have an issue that I experienced today and I had to hack around it. I think it may be a bug. When the server returns a 500 level response to the ajax call in _load_node, the ajax call is resent to the server in an infinite loop. It seems that the callback fires and sends the exact data over and over again. While I can fix the server side code for this particular instance, I need to guarantee that the client does not get in this infinite loop as it will degrade performance and bring the browser to its knees. To get around this loop I set the settings.core.data.url to "" in settings.core.data.error and later in settings.core.error I set the node.id = "#". This was a total hack, but I didn't see anything in the jstree code that gracefully handles server 500 errors without causing an infinite loop of callback requests.

+                                       'error': function(jqXHR,status,errMsg) {
+                                               jsTree.jstree().settings.core.data.url = "";
+                                               console.log(status+ " " + errMsg);
+                                       }
+                               },
+                               'error' : function (errorObj) {
+                                       var jsonData = $.parseJSON(errorObj.data);
+                                       var errorNode = jsTree.jstree("get_node",jsonData.id,false);
+                                       errorNode.id="#";
+                                       jsTree.trigger("critical_error.");
                                },
                                'multiple' : false,

Ivan Bozhanov

unread,
Feb 10, 2015, 3:39:39 AM2/10/15
to jst...@googlegroups.com
Could you please provide a bit more information:
1) Which jstree version are you using?
2) How to reproduce the issue?

I tried returning 500 for the root node - only a single request is made and the tree is left in loading state.
I tried using lazy loading and returning 500 in response to the child request - a single request is made and the node is not opened.
I tried returning 500 when the state plugin tries to restore the state - a single request was made and the problematic node was left as closed.

This could happen if you are using the almost year old 3.0.0, which had this error, but it was fixed in March last year: https://github.com/vakata/jstree/commit/bdfe0120d16df9885ea69229021917fdc055546c

Please give me more information on how to continue.

Best regards,
Ivan

Julian Russbach

unread,
Feb 10, 2015, 12:31:31 PM2/10/15
to jst...@googlegroups.com
I am using jsTree 3.0.9. I made a screencast to help illustrate the problem: https://www.youtube.com/watch?v=tZLVS1a2f1M&feature=youtu.be

Here are the steps that produce it.

1.) On the initial load of the tree I run "getNodeAndChildren". This loads the root node of the tree and its children to a depth of 1. The video shows this step already complete from 0:00 to 0:10. This is just the default presentation of the tree. The user can browse the tree and the nodes will be expanded and jstree will load them correctly. Everything is fine here. Note that the root node does not have an id associated with it, so jstree assigned the id of "j1_1". All of the children have numeric ids that were sent from the server. This is because there is no real ICD9 root node, and the root node is just there to hold the tree together.

2.) If the user does not want the default state of the tree they can search the tree. The results are returned as a full tree of filtered nodes (not just a depth of 1). This occurs @0:12. Searching the tree provides matches. In this step, everything is still ok. The functionality works great and jstree handles loading the nodes correctly.

3.) @0:32 The user clicks the "twiddle" button. This is a button I have added to each non-leaf node. When the user clicks the "twiddle" button, a request is sent to the server to get all of the children for this node regardless of the search. So for instance after searching the tree, the user decides that they want to see all of the children for a particular node, (and not just the search results), they can click the twiddle button. The twiddle button click initiates a refresh_node on the node and sends a "getChildren" request to the server.

4.) The twiddle button works correctly for me in every case except when performed on the root node. Because I have let jstree apply the id of the root node, it gives the node an id of "j1_1" however the server is looking for only numeric values for the node id. The server returns an HTTP 500 for java.lang.NumberFormatException. That is easy to fix/prevent, but it is not the server side I am worried about. After this call to "getChildren" on the root node jstree initiates an infinite loop requesting getChildren over and over again, and the server keeps sending the 500 error code.


Here is a video of the twiddle button and getChildren call working successfully. Its main purpose is to ask the server for all of the children of a node, and not just the ones that came back as matched from the initial search. It works on every node but the root node.

https://www.youtube.com/watch?v=npV8N9YvEfQ&feature=youtu.be

Thanks for the help!

Julian Russbach

unread,
Feb 11, 2015, 2:00:14 AM2/11/15
to jst...@googlegroups.com
Here are the steps stated more succinctly:
1.) load the tree with the id of the root node as null or undefined. jstree assigns the id of j1_1
2.) set root node .children to true
3.) refresh the root node triggering an AJAX call to the server to get the children.
4.) throw a 500 level HTTP response from the server.

Ivan Bozhanov

unread,
Feb 11, 2015, 3:51:49 AM2/11/15
to jst...@googlegroups.com
Thanks, I will have a look into this later today.

Best regards,
Ivan

Ivan Bozhanov

unread,
Feb 11, 2015, 8:11:36 AM2/11/15
to jst...@googlegroups.com
I was able to reproduce - the _load_nodes function is the one causing the problem, as it will trigger node loading until all nodes are loaded, even if some of the nodes failed. I will see how I will tackle this, in the mean time - if you remove the error everything will function normally.
I will let you know when the fix is in the repo.


Best regards,
Ivan

сряда, 11 февруари 2015 г., 9:00:14 UTC+2, Julian Russbach написа:

Ivan Bozhanov

unread,
Feb 11, 2015, 8:55:13 AM2/11/15
to jst...@googlegroups.com
The fix is in the repository.


Best regards,
Ivan

сряда, 11 февруари 2015 г., 9:00:14 UTC+2, Julian Russbach написа:

Julian Russbach

unread,
Feb 11, 2015, 11:57:02 PM2/11/15
to jst...@googlegroups.com
Thanks Ivan, that is great support! Thanks for jstree and the help.

Julian Russbach

unread,
Feb 13, 2015, 12:34:56 AM2/13/15
to jst...@googlegroups.com
Ах! Ти си Българин! Здраве и много благодария от мен. Аз никога бил на Пловдив, но аз бил на България шест пъти. Съпругатами е Българка. Жив и здрав!

Ivan Bozhanov

unread,
Feb 13, 2015, 10:04:59 AM2/13/15
to jst...@googlegroups.com
Благодаря и аз, много ме зарадва. Да сте живи и здрави и вие!
Reply all
Reply to author
Forward
0 new messages