Bug 45763 - After Airplane Mode turned off, web request fails for a couple of minutes with a NameResolutionFailure
Summary: After Airplane Mode turned off, web request fails for a couple of minutes wit...
Status: RESOLVED DUPLICATE of bug 45761
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 10.0 (iOS10)
Hardware: Macintosh Mac OS
: High normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-10-20 19:58 UTC by Jon Goldberger [MSFT]
Modified: 2016-10-21 10:04 UTC (History)
3 users (show)

Is this bug a regression?: Yes
Last known good build: XI

Test Project (59.45 KB, application/zip)
2016-10-20 19:58 UTC, Jon Goldberger [MSFT]
Correct Test Project (79.28 KB, application/zip)
2016-10-21 10:04 UTC, Jon Goldberger [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jon Goldberger [MSFT] 2016-10-20 19:58:57 UTC
Created attachment 18152 [details]
Test Project

## Description

This is a duplicate of Mono bug #45761. Submitting this and marking as duplicate to help anyone searching for this issue on iOS.

This is a bit of an odd issue, so bear with me. 

If this sample app is launched with a network connection and the button is tapped to send a request, the request succeeds. If then Airplane mode is enabled, the request of course fails, but upon disabling Airplane mode the next request sent succeeds right away. 

In contrast, if after app launch the first request is sent with Airplane mode enabled then the request fails with a NameResolutionFailure exception for obvious reasons (no network). However if you then disable Airplane mode and send  new request, it still fails and will continue to fail with NameResolutionFailure  exception for a couple of minutes, but eventually will succeed. 

This is a regression. Using XI the above does not occur and the first request sent immediately after network connection is restored succeeds. 

## Steps to reproduce

1. Open the attached sample app and set the iOS project as the startup project.

2. Deploy to iOS device. (turning on Airplane mode on simulator does not interrupt network connection)

3. Enable Airplane Mode (don't do this before deploying or the debugger won't be able to attach and the app won't launch)

4. Tap the "Send Request" button.

5. Label will show NameResolutionFailure message.

6. Disable Airplane mode

7. Tap the "Send Request" button.

Expected result: label text will display the ContentType of the response (text/HTML)

Actual result: label text still shows NameResolutionFailure exception. 

## Notes 

As stated, eventually if you keep tapping the button after step 7 above, the request will work after a couple of minutes. And again this does not happen with XI

The  attached sample is using a HttpWebRequest however I have another customer who reported the same issue and they were using HttpClient. 

The only difference between a version of the app that works and the version of the app that does not is the Xamarin iOS version, IOW I was able to only install  XI into the existing Cycle 8 install and then the attached test project  worked as expected. 

As an additional note, if the first request is sent without Airplane mode enabled (i.e. there is network connection) then the request succeeds, of course, but if you then enable Airplane mode and send the request, it fails with a "No Network Connection" error and if you then turn off Airplane mode again, the next request succeeds right away. 

## Environment

=== Xamarin Studio Enterprise ===

Version 6.1.1 (build 15)
Installation UUID: ceaba76c-db06-4fbd-b326-f69ea53c3e01
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/ef43c15) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010005

=== NuGet ===


=== Xamarin.Profiler ===

Version: 0.33.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.0 (11246)
Build 8A218a

=== Xamarin.Android ===

Version: (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)
		7.0   (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 24.0.3
SDK Build Tools Version: 24.0.3

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise)
Hash: ad1cd42
Branch: cycle8-sr0-xi
Build date: 2016-10-03 15:18:44-0400

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise)

=== Xamarin Inspector ===

Hash: e931a52
Branch: master
Build date: Thu, 18 Aug 2016 17:46:46 GMT

=== Build Information ===

Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

=== Operating System ===

Mac OS X 10.12.0
Darwin Jons-MacBook-Pro.local 16.0.0 Darwin Kernel Version 16.0.0
    Mon Aug 29 17:56:20 PDT 2016
    root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector
Comment 1 Jon Goldberger [MSFT] 2016-10-20 19:59:26 UTC

*** This bug has been marked as a duplicate of bug 45761 ***
Comment 2 Jon Goldberger [MSFT] 2016-10-20 20:00:14 UTC
Regression test:

Comment 3 Jon Goldberger [MSFT] 2016-10-20 20:06:42 UTC
The workaround for this would seem to be to test for network connectivity before sending your request, and to use a different url to test for connectivity than the one you need to send requests to.

You can use the Connectivity plugin for this: https://www.nuget.org/packages/Xam.Plugin.Connectivity/
Comment 4 Jon Goldberger [MSFT] 2016-10-21 10:04:15 UTC
Created attachment 18157 [details]
Correct Test Project

I accidentally uploaded the wrong test project. this is the correct one.