Sporadic server error: "A connection failure occurred"

You must Login before you can answer or comment on any questions.

Sporadically receiving this error (xhr.onerror) when making HTTP request:

Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x6e09310 {NSUnderlyingError=0x6e1c340 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)", NSLocalizedDescription=A connection failure occurred}

I'd say it works about 25% of this time, and throws this error the other 75%.

4 Answers

Accepted Answer

Just to test, could you try changing the xhr.setTimeout(0); to xhr.timeout = 10000;

— answered 4 years ago by Kosso .
answer permalink
4 Comments
  • No such luck. I'm going to attempt the impossible but stripping down the code to a very basic use case and building it back up piece by piece. If in the meantime anyone has any other suggestions, please let me know.

    P.S. A ticket has been opened with Jira.

    — commented 4 years ago by Rob Marston

  • Please see TIMOB-4495 and TIMOB-4496, which request improvements regarding the enableKeepAlive property to the documentation and SDK.

    — commented 3 years ago by Paul Dowsett

  • xhr = Titanium.Network.createHTTPClient({enableKeepAlive:false});
    Did the trick, thanks everyone!

    — commented 3 years ago by Rob Marston

  • Show 1 more comment

The most likely cause for this would be the actual device connection going down or being monetarily broken. Or the the url resource itself going down. (We all get 'fail whales' ;) )

You'd need to share more of the code you're using to do the request to see if there's anything else amiss.

— answered 4 years ago by Kosso .
answer permalink
2 Comments
  • Server logs look okay. I'm seeing the error on my device as well as in the emulator -- both have sufficient connection. This is one of many HTTP requests the app. makes but it's the only one that's problematic.

    Strange this is, I play a sound (local mp3) immediately before making the request. Removing this code seem to have improved the results. Continuing to test now.

    — commented 4 years ago by Rob Marston

  • Scratch that, didn't have any affect.

    — commented 4 years ago by Rob Marston

xhr = Titanium.Network.createHTTPClient({enableKeepAlive:false});
Seems to have done the trick. It would've been nice to've found this in the documentation. Thanks everyone!

— answered 4 years ago by Rob Marston
answer permalink
2 Comments
  • Rob

    It would be better if you would post this information as a response to Kosso's answers, so that you can mark it "best" allowing others to find it easily. The other benefit is that it shows appreciation for Kosso's efforts, as he will be awarded the Q&A points.

    Cheers

    — commented 3 years ago by Paul Dowsett

  • Ah, makes sense -- thank you Paul.

    — commented 3 years ago by Rob Marston

function play_sound() {
        if (list.contents < 5) {
            empty.play();
        } else {
            full.play();
        };
        xhr = Titanium.Network.createHTTPClient();
        xhr.setTimeout(0);
        xhr.onerror = function(e) {
            Titanium.API.info(e.error);
        };
        xhr.onload = function() {
            Titanium.API.info(this.responseText);
        };
        xhr.open('POST',uri);
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.setRequestHeader('Authorization',auth);  
        if (Titanium.Network.online) {
            xhr.send(params);
        } else {
            alert('Network unavailable, please try again.');
        };
    };
I've obfuscated some variables for security reasons.

— answered 4 years ago by Rob Marston
answer permalink
1 Comment
  • Please don't answer your own questions, Rob; use the comment facility instead. Thanks

    — commented 3 years ago by Paul Dowsett

Your Answer

Think you can help? Login to answer this question!