PDA

View Full Version : [CLOSED] time out Ext.Ajax.Request mistakenly process as valid in Chrome



meAhrendt
20 Nov 2012, 8:29 AM
I'm using ExtJS 4.1 and I'm getting an uncaught exception in Google Chrome when a timeout occurs.



Ext.Ajax.timeout = 10000; // 10 seconds
Ext.Ajax.method = "GET";
Ext.Ajax.request({
url:'rest/dataloggerset.json',
params:{
sessionGuid:Ext.getStore("User").getAt(0).get("sessionGuid"),
loggerId:this.availableLogFiles.loggerId,
logSet:this.currentLog
},
success:this.processReceivedLogData,
failure:this.failureDuringResourceLoad,
scope:this
});


The requests ends in a timeout and the so far received data is tried to be parsed in an object. So the uncaught exception that I'm seeing in the developer console looks like :

Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 Connection.js:914 Ext.define.createResponse Connection.js:914 Ext.define.onComplete Connection.js:859 Ext.define.abort Connection.js:767 request.timeout

This issue doesn't come up in FF. Due to the uncaught exception, my method failureDuringResourceLoad is not called.

After some research I've found that the xhr.abort() behaviour differs in Chrome and FF. In Chrome the xhr.status remains unchanged 200, whereas the status in FF is set to 0 after calling xhr.abort().

This difference causes an effect in ExtJS 4.1, that timedout requests mistaken as valid responses. I've used the following override to handle the timeout scenario. In ExtJS 4.1 a variable on the request objects marks if a timeout has occured. The override replaces the onComplete method.



Ext.define('Df.data.Connection', {
override: 'Ext.data.Connection',


onComplete : function(request) {
var me = this,
options = request.options,
result,
success,
response;


try {
result = me.parseStatus(request.xhr.status);
} catch (e) {
// in some browsers we can't access the status if the readyState is not 4, so the request has failed
result = {
success : false,
isException : false
};
}


success = result.success && !request.timedout;


if (success) {
response = me.createResponse(request);
me.fireEvent('requestcomplete', me, response, options);
Ext.callback(options.success, options.scope, [response, options]);
} else {
if (result.isException || request.aborted || request.timedout) {
response = me.createException(request);
} else {
response = me.createResponse(request);
}
me.fireEvent('requestexception', me, response, options);
Ext.callback(options.failure, options.scope, [response, options]);
}
Ext.callback(options.callback, options.scope, [options, success, response]);
delete me.requests[request.id];
return response;
}
});


The change can be found on line 856 in the original place in Connection.js. I've extended


success = result.success;

to :


success = result.success && !request.timedout;

If there is a more convenient way for solving this problem please let me know!

I've asked that question initially on : http://stackoverflow.com/questions/13471419/uncaught-exception-after-timeout-ext-ajax-request-in-chrome/13476325#comment18436707_13476325

Best Regards
Chris

evant
20 Nov 2012, 3:12 PM
I can't reproduce this using 4.1.1 (or the latest code) on Chrome 23.0.1271.64 m



Ext.require('*');

Ext.onReady(function() {
Ext.Ajax.timeout = 3000;
Ext.Ajax.request({
url: 'data.php',
success: function(){
console.log('success');
},
failure: function(response){
console.log('failure', response.timedout, response.status, response.aborted);
}
});
});




<?php
sleep(10);
?>


When I run it, it ends up logging:



failure true 0 undefined


Please post more information.

lager
21 Nov 2012, 12:20 AM
I've just found this in production.

ExtJS 4.1 and Mac OSX 1.0.7.4 with Chrome 22.0.1229.94

The trick is to get the request to timeout while receiving data, not while waiting or connecting.

meAhrendt
21 Nov 2012, 12:32 AM
sorry, forgot to add this here :

The problem occurs exactly as you say lager, when data is still being received.

meAhrendt
21 Nov 2012, 1:33 AM
Ext version tested:

Ext 4.1 Build date: 2012-04-20 14:10:47 (19f55ab932145a3443b228045fa80950dfeaf9cc)
Browser versions tested against:

Chrome Version 23.0.1271.64
DOCTYPE tested against:

Description:

see above
Steps to reproduce the problem:

post AJAX request - force timeout during data transmission
The result that was expected:

on timeout failure callback should be called
The result that occurs instead:

failure callback was not called on timeout

Possible fix:

see above
Operating System:

MacOS X 10.8.2

mpuccerella
31 Mar 2014, 6:49 PM
Is there an update on this?

evant
31 Mar 2014, 8:07 PM
I was never able to reproduce this, has anyone been able to come up with a reliable way to make this happen?