{"action":"created","issue":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/2199","labels_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/2199/labels{/name}","comments_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/2199/comments","events_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/2199/events","html_url":"https://github.com/pouchdb/pouchdb/issues/2199","id":33136309,"number":2199,"title":"Too high recursion error in firefox and safari windows","user":{"login":"trokster","id":673371,"avatar_url":"https://avatars.githubusercontent.com/u/673371?v=3","gravatar_id":"","url":"https://api.github.com/users/trokster","html_url":"https://github.com/trokster","followers_url":"https://api.github.com/users/trokster/followers","following_url":"https://api.github.com/users/trokster/following{/other_user}","gists_url":"https://api.github.com/users/trokster/gists{/gist_id}","starred_url":"https://api.github.com/users/trokster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trokster/subscriptions","organizations_url":"https://api.github.com/users/trokster/orgs","repos_url":"https://api.github.com/users/trokster/repos","events_url":"https://api.github.com/users/trokster/events{/privacy}","received_events_url":"https://api.github.com/users/trokster/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pouchdb/pouchdb/labels/help%20wanted","name":"help wanted","color":"02e10c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2014-05-09T00:12:58Z","updated_at":"2015-07-05T17:14:48Z","closed_at":"2015-07-05T17:14:48Z","body":"Hi,\r\n\r\nI've encountered this error upon replicating a high rev doc ( around 300 revs ): it gets stuck at tree1[2].sort(). I've seen this issue pop up a few times in the issues forum so I figured I'd try replacing native sort with a custom non recursive one.\r\n\r\n( firefox 29, ubuntu. windows safari 5.1.7 )\r\n\r\nIt worked for firefox. Not sure how to validate solution.\r\n\r\nBelow is used alternate sort, copied from a gist I can't alas locate anymore:\r\n\r\nfunction qsort(a, l, r) {\r\n  // a: array to sort\r\n  // l, r: optional array index array range\r\n\r\n  // i: stack index, s: stack,\r\n  // p: pivot index, v: pivot value,\r\n  // t: temporary array item,\r\n  // x, y: partion low/high\r\n\r\n  var i, s, p, v, t, x, y;\r\n\r\n  l = l || 0;\r\n  r = r || a.length - 1;\r\n\r\n  i = 2;\r\n  s = [l, r];\r\n\r\n  while (i > 0) {\r\n    r = s[--i];\r\n    l = s[--i];\r\n\r\n    if (l < r) {\r\n      // partition\r\n\r\n      x = l;\r\n      y = r - 1;\r\n\r\n      p = l;\r\n      v = a[p];\r\n      a[p] = a[r];\r\n\r\n      while (true) {\r\n        while (\r\n          x <= y &&\r\n          a[x] != undefined &&\r\n          (\"\"+a[x]) < (\"\"+v) )\r\n          x++;\r\n        while (\r\n          x <= y &&\r\n          a[y] != undefined &&\r\n          (\"\"+a[y]) >= (\"\"+v))\r\n          y--;\r\n        if (x > y)\r\n          break;\r\n        t = a[x];\r\n        a[x] = a[y];\r\n        a[y] = t;\r\n      }\r\n\r\n      a[r] = a[x];\r\n      a[x] = v;\r\n\r\n      // end\r\n\r\n      s[i++] = l;\r\n      s[i++] = x - 1;\r\n      s[i++] = x + 1;\r\n      s[i++] = r;\r\n    }\r\n  }\r\n}\r\n\r\n\r\nmy two cents."},"comment":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/comments/118638909","html_url":"https://github.com/pouchdb/pouchdb/issues/2199#issuecomment-118638909","issue_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/2199","id":118638909,"user":{"login":"daleharvey","id":37787,"avatar_url":"https://avatars.githubusercontent.com/u/37787?v=3","gravatar_id":"","url":"https://api.github.com/users/daleharvey","html_url":"https://github.com/daleharvey","followers_url":"https://api.github.com/users/daleharvey/followers","following_url":"https://api.github.com/users/daleharvey/following{/other_user}","gists_url":"https://api.github.com/users/daleharvey/gists{/gist_id}","starred_url":"https://api.github.com/users/daleharvey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daleharvey/subscriptions","organizations_url":"https://api.github.com/users/daleharvey/orgs","repos_url":"https://api.github.com/users/daleharvey/repos","events_url":"https://api.github.com/users/daleharvey/events{/privacy}","received_events_url":"https://api.github.com/users/daleharvey/received_events","type":"User","site_admin":false},"created_at":"2015-07-05T17:14:48Z","updated_at":"2015-07-05T17:14:48Z","body":"Consolidating on one issue, we have mostly fixed these but want to keep one open https://github.com/pouchdb/pouchdb/issues/3225"}}