[TIMOB-1042] Regression in HTTPClient/1.3

GitHub Issuen/a
Resolution Date2011-04-17T01:55:02.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.4.0
Labelshttpclient, iphone
ReporterDamien Elmes
AssigneeReggie Seagraves


My code is accessing a web service which compresses a large file then sends it over the wire gzipped. It takes about 20 seconds for the web service to reply. More often than not, the download fails when running on 1.3 (it works fine on 1.2.0). It seems the first few packets come in (ondatachange is called a few times), then an exception is raised. Timeout on the connection is set to 2 minutes, well above the time it takes to fail.

I ran the program in a debugger and got the following backtrace:

#0  0x9738e4e6 in objc_exception_throw ()
#1  0x02a04c3b in +[NSException raise:format:arguments:] ()
#2  0x02a04b9a in +[NSException raise:format:] ()
#3  0x004aecc9 in _NSArrayRaiseBoundException ()
#4  0x0044c2e5 in -[NSCFArray insertObject:atIndex:] ()
#5  0x0044c284 in -[NSCFArray addObject:] ()
#6  0x00035a3a in -[KrollBridge registerProxy:] (self=0x5322c00,
_cmd=0x91e26897, proxy=0x5374be0) at
#7  0x0008690b in -[TiProxy _initWithPageContext:] (self=0x5374be0,
_cmd=0x296ac0, context=0x5322c00) at
#8  0x00089e0d in -[TiNetworkHTTPClientResultProxy initWithDelegate:]
(self=0x5374be0, _cmd=0x9729fe90, proxy=0x50316d0) at
#9  0x0008c2ed in -[TiNetworkHTTPClientProxy setProgress:upload:]
(self=0x50316d0, _cmd=0x28e84d, value=0.0317440554, upload=0 '\000')
at /Users/ema/Desktop/mobanki/Anki/build/iphone/Classes/TiNetworkHTTPClientProxy.m:443
#10 0x029c072d in __invoking___ ()
#11 0x029c0618 in -[NSInvocation invoke] ()
#12 0x029e5158 in -[NSInvocation invokeWithTarget:] ()
#13 0x0000fb6c in +[ASIHTTPRequest
setProgress:forProgressIndicator:upload:] (self=0x2e1c00,
_cmd=0x28f216, progress=0.031744055987380317, indicator=0x50316d0,
upload=0 '\000') at
#14 0x0000f711 in -[ASIHTTPRequest updateDownloadProgress]
(self=0x5031950, _cmd=0x28d587) at
#15 0x0000e884 in -[ASIHTTPRequest updateProgressIndicators]
(self=0x5031950, _cmd=0x28d5fb) at
#16 0x0000def9 in -[ASIHTTPRequest loadRequest] (self=0x5031950,
_cmd=0x28d65a) at
#17 0x0000b79f in -[ASIHTTPRequest main] (self=0x5031950,
_cmd=0x9736ec8e) at
#18 0x004bdb25 in -[NSOperation start] ()
#19 0x00450f7d in -[NSThread main] ()
#20 0x00450b18 in __NSThread__main__ ()
#21 0x92a7ba19 in _pthread_start ()
#22 0x92a7b89e in thread_start ()
Current language:  auto; currently objective-c




  1. Jeff Haynie 2011-04-15

    would it be possible to get the URL to your gzip for testing? If not, that's fine - just give me more details about the size so i can try and re-create. thanks

  2. Damien Elmes 2011-04-15

    Here's the code to reproduce it:

       var debug = Ti.API.debug;
       var file = Titanium.Filesystem.getFile(
           Titanium.Filesystem.applicationSupportDirectory + "/tmp.file");
       // work around the bug where onload events are sometimes not delivered
       var utils = {};
       utils.clearXhrTimer = function () {
           if (utils.currentXhrTimer) {
               utils.currentXhrTimer = null;
       // a 6MB file to demonstrate the problem
       var url = "http://ankisrs.net/tmp/";
       var xhr;
       function downloadFile() {
           xhr = Titanium.Network.createHTTPClient();
           xhr.onerror = function(e) {
               alert("Error: " + e.error);
           xhr.onload = function() {
               try {
                   if (xhr.status == 200) {
                       if (file.exists()) {
               } catch (err) {
                   alert (err);
           xhr.ondatastream = function (e) {
           utils.currentXhrTimer = setInterval(
               function () {}, 1000);
           xhr.open('POST', url);
  3. Damien Elmes 2011-04-15

    (it's actually 40MB of random data zipped this time, but same problem)

  4. Jeff Haynie 2011-04-15

    OK, i'll take a look at this ASAP.

  5. Jeff Haynie 2011-04-15

    tried 5-6 times to reproduce ... seems to work all the time. no crashes...

    can you possibly try building and testing from head?

  6. Damien Elmes 2011-04-15

    Compiled from head - at first I thought I'd done something wrong as you've made the build process much faster! I'm assuming the version # is supposed to be 1.3.1?

    Unfortunately the problem is still there. I discovered that I'd set the delay to 2 seconds during testing. I was still able to reproduce it with that short delay, but I've set it back to 20 seconds now in case it's a timing issue. Could you give it another go?

    I also tried creating a new project and copying the code above into app.js (deleting the default stuff), and still got the problem.

  7. Damien Elmes 2011-04-15

    Did some more testing. I can reproduce this every time when running from the simulator, but was unable to reproduce this even one when running on a device. If I comment out the ondatastream function, the error doesn't occur either. I guess it's a race condition?

  8. Damien Elmes 2011-04-15

    I've been trying to squeeze a bit more performance out of HTTPClient - download speeds are about 3x slower on a device than in the simulator, both running of the wireless network. Perhaps I'm just being unrealistic about what a 2nd gen touch can do. I have a 1st gen touch which is much slower again, but it's been acting funny recently, so I'm not sure if its poor performance is due to a hardware fault or not.

    Anyway, I wrote a patch to reduce the frequency the progress handlers were called, in the hope that would speed things up. I ended up reverting it because it had a negligible impact on download speed, but one nice side effect it had was to stop this problem from popping up. I mention it in case that makes it any easier to debug. OTOH, since this doesn't seem to appear outside the simulator, it's not a big deal.

    http://github.com/dae/titanium_mobile/commit/f6a50354b4f6987d9035762837b9648730bedb28"> http://github.com/dae/titanium_mobile/commit/f6a50354b4f6987d903576...

  9. Jeff Haynie 2011-04-15

    can you try with the latest from master?
    i've updated to the latest ASIHTTPRequest which seems to have some performance improvements.

  10. Damien Elmes 2011-04-15

    The latest ASI has fixed the download issue I was seeing in the emulator (and I saw it happen once on a real device, but only once), so you can mark this issue as closed now. Thanks for the fix!

JSON Source