Not sure what the deal is with this. I arbitrarily get this error:
Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found."
Reachability hasn't changed at that point, and a successful request will come before and after this. The hostname definitely isn't going away. I can hit the url for eternity and repeatedly with curl.
I’ve been experiencing this exact same sporadic kCFURLErrorCannotFindHost (-1003) error today when connecting to an app hosted on heroku.
Of note I am on heroku as well. Can you reproduce it with curl, or just the app?
On May 3, 2013, at 4:37 PM, Cédric Luthi [email protected] wrote:
I’ve been experiencing this exact same sporadic kCFURLErrorCannotFindHost (-1003) error today when connecting to an app hosted on heroku.
—
Reply to this email directly or view it on GitHub.
I’ve been experiencing sporadic getpeername() failed with errno 57 errors with curl as well. It looks like it could be curl’s equivalent to kCFURLErrorCannotFindHost. So this is most likely a problem with heroku.
Interesting. @sprynmr and I were discussing our mutual exposure to this of late on IRC. I also host GateGuru production and staging on Heroku. Luckily, we may just have access to someone who can provide insight… @mattt ?
@blakewatters I floated this over to our routing teams to see if they knew what could be causing this.
We have experienced the same problem a bunch of times in the last period. Our app is running on Heroku too (1 web dynos, 0 worker dynos)
@r4m This may be caused by your dynos being idled, and the timeout being set such that the request fails before the dyno reawakens. Not sure what could be causing this for everyone else, though...
We're running on 1 for now as well, but the failures come while it's not idle, after several other successful requests (often in rapid succession). Even if one's dyno were to time out before spinning up, it shouldn't be the host not found error I wouldn't think.
Shouldn't matter, but what servers are people running? We are on Jetty.
I quote @sprynmr, we had the same situation: the error appeared after several other successful requests so I'd not think that it depends on an idle state.
I’ve been experiencing the exact same issue when connecting to https://www.youtube.com so maybe this issue is not related to heroku.
So we solved our problem. It had nothing to do with AFNetworking (except for maybe reporting the wrong error, which might be an Apple problem). For us, our gzip process on the server was screwed up. It was gzipping, but not updating the content-length. So sometimes the response would seem to end early, and presumably NSURLConnection would get confused and throw an error. This happened intermittently for some reason (perhaps due to the points where the server might chunk gzip depending on the length of the response).
Anyway, once that was solved, no more errors. In fact, it solved my weird Charles Proxy error I was having as well and reported over at RestKit https://github.com/RestKit/RestKit/issues/1383
I'm closing this, but if you guys keep experiencing issues you might want to open another issue.
It means using Gzip is unsafe?
No. Our particular implementation was messed up and was reporting the wrong content-length when gziping. Gzip should be fine.
In the meantime we've noticed a very occasional -1003 error (host name not found) even with our fix, which corrected most of our problems. I believe this is a heroku error and nothing to do with afnetworking.
Same issue using Restkit and heroku. Anyone find a true solution?
@jgervin No. Still have the same problem occasionally. My solution was to retry the request if the 1003 error came back. I would reopen this, but I'm pretty sure it's a heroku error.
That is exactly what I just did.
@mattt You ever hear anything from the routing team on what this might be?
@sprynmr The Heroku routing team is investigating the issue, but has not found any evidence of specific behavior that would cause this. Since @0xced reported similar behavior for YouTube, I suspect that this could be an instance of response bias, since GitHub-savvy AFNetworking users appear to be more likely to use Heroku.
@mattt It would seem like this would be a pretty widely reported bug if it was happening for everyone using AFNetworking, or everyone using the networking straight out of iOS. But maybe not. Do you have any thoughts as to what it might be if not heroku related?
@sprynmr I also done the retry logic, but it seems that a specific device or network will always appear
Just want to add that I'm experiencing this as well in my iOS project, without using AFNetworking, and my API is hosted on Heroku. I get it when using a plain NSURLRequest.
i'm using RestKit and therefore AFNetworking, and i've been experiencing the same thing. i have a scala web app deployed with heroku, and it's definitely not the dyno spinning up issue -- i've seen that of course, but the "server with the specified hostname could not be found" issue even happens seconds after a previous attempt succeeds fine. it's very irregular -- it happened half the time for a few minutes, then everything was fine for 20 minutes after.
I had to write some echo code that calls my important calls twice, if the first time fails with this error.
Jason
Stat.com
On Jul 25, 2013, at 2:40 PM, Benjamin Wheeler [email protected] wrote:
i'm using RestKit and therefore AFNetworking, and i've been experiencing the same thing. i have a scala web app deployed with heroku, and it's definitely not the dyno spinning up issue -- i've seen that of course, but the "server with the specified hostname could not be found" issue even happens seconds after a previous attempt succeeds fine. it's very irregular -- it happened half the time for a few minutes, then everything was fine for 20 minutes after.
—
Reply to this email directly or view it on GitHub.
We're using AFNetworking in our project and in our log I've noticed the (random) -1003 error messages.
We're not using Heroku. Could this be a HTTPS thing?
Any updates on this? We are seeing this in an iOS app using a Heroku backend.
I've managed to find the source of our problem:
We are using a multipart form post request to send our DDLog files to our server. The request would often fail when DDLog was persisting the logs to disk while AFNetworking was building the form data (appendPartWithFileURL)
Perhaps the issue here is that AFNetworking is first setting the body length using the file size provided by the file info and after that reads the file content using streams. This could lead to reported body length != file content size.
I am facing same issue,
On Simulators its works fine, but sometime on device its give this error.
I have so many projects using Heroku and restkit all works fine( all have valid certificate). But one client project is not using valid certificate and I am facing this issue for that project. So I think its related to https + Invalid Certificate.
Experiencing the same phantom error. We are using an Azure backend. I am experiencing it intermittently but my coworker is seeing it all the time.
Is this solved? I am seeing this error on device using http server.
I have the same problem, but I'm using AWS (Amazon)
I'm experiencing same issue, and using Amazon AWS EC2 micro instance. Getting this error randomly, but quite often, which effect our application start.
What would be the best way to deal with this issue until its properly fixed?
Though, issue exist for over a year already.
Is this solved? We use AWS and we have the same issue.
In our case, this is not AFNetworking issue. There is some problem with DNS server reached through our WiFi network. So we change DNS server and fix this problem.
I'm experiencing same issue. Getting this error randomly, when I request something from my server. So, I am add some log in my proj.
When it occur, I ping my server domain and ip. Ping IP is success but domain not.
So, I think it maybe dns resolved error.
My case is reproducible - I don't get it the first request after launching my app. But I am consistently getting it every second time and onwards intermittently. My server is running on EC2 and doesn't have any DNS issue. In fact, I get the same error if I change the hostname to IP address in the URL.
Same for me,
In my case this error occurs only when I'm using background app refresh on a real device. I cannot reproduce this but I'm thinking that it could happen when 3G/GSM is used and connection is unstable eg. content-length = 100500, while only part of the data was received. Would try to play with Network Link Conditioner today
Upd: After some digging through applications logs I found that actually GET request is failing, and it happens even using WiFi, so there should be nothing related to Content-Length. While I cannot reproduce it locally, still on iOS8 it is failing like everyday. Network Link Conditioner brought me nothing, so I would try to setup NSURLProtocol that would log all the requests and responses, hopefully I would catch the issue.
We are experiencing the same error, - can't believe this issue has been open for longer than a year and no solution yet.
We are using RestKit (and hence AFNetworking) + Heroku backend.
Any success on this issue?
@anshusrii Try disabling all the HTTP proxies between the server and your iOS client app. This should help resolve the error. This particularly applies to HTTP debugging proxies like CharlesProxy, or "mitmproxy".
I significantly reduced, if not completely eliminated, such error by pointing directly to heroku service URL. That is, instead of pointing to api.mydomain.com (which is a CNAME of myapp.herokuapp.com), I just use myapp.herokuapp.com directly.
I also get this error every 10 minutes, mostly on wifi but not able to find any solution not even using heroku. I am using NSURLConnection ,
Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo=0x7fdbd3c48610 {NSUnderlyingError=0x7fdbd60a5e80 "A server with the specified hostname could not be found.", NSErrorFailingURLStringKey=http://hostname/api/methodname, NSErrorFailingURLKey=http://hostname/api/methodname, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSLocalizedDescription=A server with the specified hostname could not be found.}
Is there any solution for this ? It works fine in Android at the same time using same API.
We've also had this issue. Happens randomly. We are also using Heroku, but have 2 dynos so the idle theory should be ruled out. User was connected to Verizon, LTE with 2 bars.

Has anyone tried changing the cache policy to NSURLRequestReloadIgnoringCacheData ?
I also got this error at times, but I can't find the solution。
I am experiencing this issue as well but in my case, it did not seem to be an issue before iOS 9.
Also, turning off wifi and using 3G makes the error go away which i find to be very strange.
I have also fetch this same issues many time. But, in my case when i switch to another WiFi network or Switch ON/OFF WiFi then it was automatically solved. Please try that and let us know your comments. Thanks!
I found this thread via Googling the same error message. I'm not using Heroku or AFNetworking, however I was receiving the same errors in the simulator and device.
I tried @chintan100 and @renish007 's suggestion of switching networks on the device (switched to cellular instead of wifi) and it seems to work. When on wifi it works intermittently.
so anyone figure this out?
I have an Apache server and I use AFNetworking. This is my use case:
I started to notice this problem when the server side cache started to be full, when I cleaned the server side cache I didn't notice anything more
I would like to pitch in here.
I've been dealing with (presumably) this error for over a year. Here are some facts:
Service runs on AWS Elastic Beanstalk (using custom domain CNAME) with ELB.
SSL Certificate pinned/hardcoded into app (although issue was present before this was implemented).
Never, ever any issues with browsing the website (which runs on the same servers).
Problem has been present on all versions of iOS (7-9 in my case).
No third party connection libraries (AFNetworking etc.). Only native NSURLConnection objects.
Problem does not occur on all devices at the same time. Just randomly one device will fail all requests while another one at the same time works just fine. The failing device can browse websites, use Facebook etc. without issue.
Here's the really odd part:
It happens very randomly and never for myself. I don't know what my users are doing to provoke this error, but I cannot for the life of me make my own devices fail. I get the exact error screenshot above by fraggle222. The times I've experienced it on other devices it requires either a full reboot of the phone or enabling/disabling Flight mode. Going to/from Wifi/3G/4G does not help. Restarting the app itself does not help.
Really at my wits end with this.
I fixed my issue by changing the cache policy to NSURLRequestReloadIgnoringCacheData . I noticed, like someone on this thread, that the issue in our cases was cache related.
@mijiapps - I will try that. Thanks.
@mijiapps - That did not resolve the issue. I still get error 1003. Nothing changed.
Hi, who anyone solve this probelm..I still get error -1003 while using AFNetwork. If Someone has solution can share it ?
Hi, I met a problem . error=Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found."
I got this error always after upgrading to iOS 9.3.4. The strange part is that I use IP address (not domain name) to access the server, so there should't be any DNS resolution involved.
One thing that I've noticed is that my IP address was prefixed with "www.". This way it would never work!
If you prefix an IP address with www. it will be treated as a DNS-name, giving a DNS error.
I don't understand - did you fix it by finding out that you had prefixed www, or?
Sent from my iPhone
On 09 Aug 2016, at 02:17, Dariusz ?uksza <[email protected]notifications@github.com> wrote:
I got this error always after upgrading to iOS 9.3.4. The strange part is that I use IP address (not domain name) to access the server, so there should't be any DNS resolution involved.
One thing that I've noticed is that my IP address was prefixed with "www.". This way it would never work!
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/AFNetworking/AFNetworking/issues/967#issuecomment-238416746, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYsjRHvS8xfa-p6S8m3ANIYq62q1s5ks5qd8cNgaJpZM4AoPl4.
I have the same issue when my app run on iOS10.2 and conneting to a https hostname .When I open this https hostname on safari ,it show me Invalid certificate.So I changed the SSL certificate and it worked!
@nickdnk did you end up resolving your issue? I am experiencing the _exact_ same problem you are having. Your insight is much appreciated!
After switching to NSURLSession this went away. I never figured it out. I used NSURLConnection. Sorry.
Sent from my iPhone
On 24 Jan 2017, at 00.20, sonypop <[email protected]notifications@github.com> wrote:
@nickdnkhttps://github.com/nickdnk did you end up resolving your issue? I am experiencing the exact same problem you are having. Your insight is much appreciated!
-
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/AFNetworking/AFNetworking/issues/967#issuecomment-274649887, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYsidtg2RhFXaO_UMOmjueM3SNQalKks5rVTXAgaJpZM4AoPl4.
Thanks for the heads up anyway!
have this problem on iOS 10.x.x
I think this issue should not be closed.
Happened randomly
for me it happens when users switch from wifi to 4g, and even then they have to use 4g for a while before the issue presents itself and shows the -1003 ""A server with the specified hostname could not be found" issue.
After some debugging i discovered when this error occurs, afnetworking reports reachability status as unknown. I read somewhere that if reachability is unknown all the operation queues are suspended hence why the the -1003 error is occurring. im trying to find out why afnetworking is reporting reachability as unknown when the phone is connected to 4g, but is okay when connected to wifi.
I am seeing this error with AFNetworking on iOS 11.+ connecting to a Rest web API that was built using asp.net and is hosted on IIS 10. No Gzip involved. The web API is behind a jetnexus load balancer. We connect to the API over HTTP and HTTPS. I am seeing the error on http request.
fyi, the problem for us was the ttl in our dns entry was set too low (60 seconds) increasing it to 24 hours fixed the issue
Ekan, if the TTL runs out, a subsequent request should trigger a new DNS lookup, thus returning the correct IP (if it even changed).
Sent from my iPhone
On 8 Nov 2017, at 22.51, Ekan Egonmwan <[email protected]notifications@github.com> wrote:
fyi, the problem for us was the ttl in our dns entry was set too low (60 seconds) increasing it to 24 hours fixed the issue; the dns servers when using 4g probably dont refresh as often as every 60 seconds
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/AFNetworking/AFNetworking/issues/967#issuecomment-342972046, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYsoUz5mUd3UZIIGuALTYimlNL2uRMks5s0iJCgaJpZM4AoPl4.
@nickdnk not sure sure how often the dns servers 4g use refresh their cache, but once the ttl runs out, the entry probably gets deleted hence "A server with the specified hostname could not be found."
And in that case, a request to said server (where the entry has expired) should be forwarded to another DNS server and then live until the TTL runs out again.
I’m not saying your solution cannot work, but the explanation makes no sense, technically.
On 8 Nov 2017, at 23.08, Ekan Egonmwan <[email protected]notifications@github.com> wrote:
@nickdnkhttps://github.com/nickdnk not sure sure how often the dns servers 4g use refresh their cache, but once the ttl runs out, the entry probably gets deleted hence "A server with the specified hostname could not be found."
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/AFNetworking/AFNetworking/issues/967#issuecomment-342977073, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYsjbji0ZH1hdEtUjeIsN114e253vqks5s0iZegaJpZM4AoPl4.
And in that case, a request to said server (where the entry has expired) should be forwarded to another DNS server and then live until the TTL runs out again.
I’m not saying your solution cannot work, but the explanation makes no sense, technically.
Hmmm, when you say "should be forwarded", this is entirely dependent on the dns settings when running on 4g right? and even the implementation of the dns server when it comes to caching
If the DNS server is broken, then yes it is a configuration issue. But if properly set up, a DNS server should always forward queries for hostnames it cannot resolve. I suspect there may be rate-limiting functionality set in place on some servers to avoid excessive forwards for non-existing domains, but that shouldn’t affect legitimate traffic.
Sent from my iPhone
On 8 Nov 2017, at 23.27, Ekan Egonmwan <[email protected]notifications@github.com> wrote:
And in that case, a request to said server (where the entry has expired) should be forwarded to another DNS server and then live until the TTL runs out again.
I’m not saying your solution cannot work, but the explanation makes no sense, technically.
Hmmm, when you say "should be forwarded", this is entirely dependent on the dns settings when running on 4g right? and even the implementation of the dns server when it comes to caching
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/AFNetworking/AFNetworking/issues/967#issuecomment-342981896, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIBYsh24gsTd3uULwWbvbmUoaKXsu9C6ks5s0irrgaJpZM4AoPl4.
Most helpful comment
I would like to pitch in here.
I've been dealing with (presumably) this error for over a year. Here are some facts:
Service runs on AWS Elastic Beanstalk (using custom domain CNAME) with ELB.
SSL Certificate pinned/hardcoded into app (although issue was present before this was implemented).
Never, ever any issues with browsing the website (which runs on the same servers).
Problem has been present on all versions of iOS (7-9 in my case).
No third party connection libraries (AFNetworking etc.). Only native NSURLConnection objects.
Problem does not occur on all devices at the same time. Just randomly one device will fail all requests while another one at the same time works just fine. The failing device can browse websites, use Facebook etc. without issue.
Here's the really odd part:
It happens very randomly and never for myself. I don't know what my users are doing to provoke this error, but I cannot for the life of me make my own devices fail. I get the exact error screenshot above by fraggle222. The times I've experienced it on other devices it requires either a full reboot of the phone or enabling/disabling Flight mode. Going to/from Wifi/3G/4G does not help. Restarting the app itself does not help.
Really at my wits end with this.