• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSURLConnection callbacks in the presence of errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection callbacks in the presence of errors


  • Subject: Re: NSURLConnection callbacks in the presence of errors
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 10 Jan 2014 10:13:25 -0800


On Jan 10, 2014, at 4:07 AM, Quinn The Eskimo! <email@hidden> wrote:

Most of Jens's comments are spot on, but this is wrong, at least on modern systems.  I tested this with a test app running in the iOS 7 simulator and "nc" running on my Mac.

Huh. My hypothesis had been that this applied to all chunked responses, but maybe there are other factors involved too.

The bug I filed in April 2012 was rdar://11352176, which was closed as a dup of rdar://8971926, which is still open.

There’s a simple test case attached, which still fails for me today on OS X 10.9.1. It tries to get a changes-feed from a public CouchDB server and never gets any data back. Here’s what the server is sending:

$  curl -i --raw 'http://snej.iriscouch.com/nsurlconnection_test/_changes?feed=continuous&heartbeat=300000'
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Server: CouchDB/1.3.0 (Erlang OTP/R15B03)
Date: Fri, 10 Jan 2014 17:56:53 GMT
Content-Type: text/plain; charset=utf-8
Cache-Control: must-revalidate

6b
{"seq":1,"id":"017384e1ea0b97d252344df2310001e7","changes":[{"rev":"1-4c6114c65e295552ab1019e2b046b10e"}]}

(At this point the server stops sending data but leaves the socket open; this is a continuous feed where it sends a chunk every time there’s a server-side event.)

We may actually be seeing the same behavior. I notice that in your example the delegate’s data callback wasn’t invoked until your fake server had sent about 512 bytes of response. In my test case the response is shorter than that. So it looks like there’s no reasonable timeout on the buffering, meaning that streamed responses of this nature don’t get delivered to clients in a timely manner. Even if the changes-feed were longer, chances are the last couple of events wouldn’t be sent because they’re still sitting in the buffer. This makes NSURLConnection useless for this purpose.

I’ve spent significant time working around this issue over the past 18 months, by the way. First diagnosing it, then writing a workaround in the form of a CFStream-based HTTP client with its own chunked-mode parser. I don’t say this to whine, just to point out that to me this has been a serious issue.

—Jens

PS: Also FYI, NSURLConnection isn’t the only HTTP client code with this problem. I’ve seen similar misbehavior in some HTTP proxies/gateways.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSURLConnection callbacks in the presence of errors
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
References: 
 >Re: NSURLConnection callbacks in the presence of errors (From: Jens Alfke <email@hidden>)
 >Re: NSURLConnection callbacks in the presence of errors (From: "Quinn \"The Eskimo!\"" <email@hidden>)

  • Prev by Date: Re: NSURLConnection callbacks in the presence of errors
  • Next by Date: Re: NSURLConnection callbacks in the presence of errors
  • Previous by thread: Re: NSURLConnection callbacks in the presence of errors
  • Next by thread: Re: NSURLConnection callbacks in the presence of errors
  • Index(es):
    • Date
    • Thread