A bug in asihttprequest and 30 seconds timeout

Source: Internet
Author: User

Today, an asihttprequest bug is found in the project. This bug may cause your HTTP request latency to be at least after the time specified in timeout. What's even more terrible is that it may waste more time for programmers to find out this bug. I have struggled for at least three hours to solve this problem!

The project has been using asihttprequest, but once I found that HTTP requests always fail. I subconsciously thought this was a network latency problem. I extended the asihttprequest timeout time to 30 seconds, so the program no longer reports an error.

But when I used the same code today, I found that I was all wrong. This is not a timeout issue, but a bug in asihttprequest.

This time, I requested a JSP page of the local Tomcat server. The page code is very simple and the response time for requesting this page in Firefox will not exceed 0.01 seconds, however, it took more than 20 seconds to return in the iPhone simulator. This cannot be the cause of network latency.

When I change the timeout time to 10 seconds and wait for the timeout time to end, asihttprequest even directly reports the kcfstreameventerroccurred error.

I opened all the debugging logs of asihttprequest and found that asihttprequest seemed to be trying to connect to the server with the last connection:

Request #3 will use connection #2

Request attempted to use connection #2, but it has been closed -will retry with a new connection

Request #3 will use connection #3

 

It seems that the last HTTP connection is reused during the connection. This is definitely not acceptable, because the server has closed the connection after the last HTTP request.

So we can only disable connection reuse of asihttprequest:

[Requestsetshouldattemptpersistentconnection: No];

In this way, the previous problems will not occur. In fact, persistentconnection should not be enabled in different HTTP sessions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.