1

I'm loading some JSON data from an AJAX query:

       $.ajax({'url': url, type: params.method, 'data': data, timeout: this.settings.timeout, success: function(d,a,x){
                console.log('request Complete',params.endpoint,params.params);
                var json = null;
                try {
                    json = JSON.parse(d);
                } catch(e) {
                    console.error(e);
                }
                console.log('json');

                // omitted for brevity...
            }
        });

I'm seeing occasional "Aw, Snap" crashes in chrome where the last console.log is the "request Complete" (the error or 2nd log never get shown).

I suppose that it's important to note that the data may be large (sometimes as big as ~15Mb), which is why I'm not printing out d on every request and looking for malformed JSON (yet... I may result to that). FWIW, I've also tried $.parseJSON instead of JSON.parse

Research I've done into the "Aw, Snap" error is vague, at best. My best guess atm is that this is an OOM. Unfortunately, there's not much I can do to decrease the footprint of the result-set.

Is there any way I could, at the least, gracefully fail?

Zane Claes
  • 14,732
  • 15
  • 74
  • 131

2 Answers2

2

What happens when you tell jQuery the response data is JSON via the dataType property? Doing so should cause jQuery to pre parse and just give you the data. If you're right about what is going on, it seems this might cause a crash too. jQuery does some sanity checks before parsing, though.

$.ajax({
    url: url,
    type: params.method,
    data: data,
    dataType: 'json',
    timeout: this.settings.timeout,
    success: function (d, a, x){
        // `d` should already be parsed into an object or array, and ready to use
    }
});

If that doesn't help, please post your actual JSON response for us to take a look at.

JAAulde
  • 19,250
  • 5
  • 52
  • 63
  • I hadn't considered that the jQuery parsing might perform extra checks; I'll try this and see if the issue is resolved (might take some time to be sure). – Zane Claes Feb 15 '13 at 17:06
0

"@the system" nailed it. 15MB of info coming back is too much for your browser to handle. I tripped upon this trying to see why my 64 Byte encoded image string is crashing the chrome tab, and it's only 200-500KB.

To 'gracefully fail', it seems you will need to have server side logic in place to prevent this from happening; perhaps limit the size of the JSON string. Only have X characters of length in the initial JSON string and add a property for 'isFinishedSending: false' or 'leftOff: [index/some marker]' so you can timeout for a bit and hit your server again with the the place you left off.

webdevinci
  • 310
  • 3
  • 10
  • This looks like it might be better suited to be a comment rather than posted as an answer. – Kmeixner Feb 29 '16 at 18:26
  • it should... i dont have the rep to comment... silly silly system. kind of caters to having me create issues that aren't really issues just to get someone to answer – webdevinci Mar 01 '16 at 20:22