Bug 46792 - Http requests do not work when wifi is toggled off and back on
Summary: Http requests do not work when wifi is toggled off and back on
Status: RESOLVED DUPLICATE of bug 45761
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries (show other bugs)
Version: XI 10.2 (iOS 10.1)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Manuel de la Peña
URL:
: 40104 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-11-11 14:20 UTC by Danny Cabrera
Modified: 2017-02-06 15:25 UTC (History)
10 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Http Client Sample (563.83 KB, application/zip)
2016-11-11 14:20 UTC, Danny Cabrera
Details

Description Danny Cabrera 2016-11-11 14:20:01 UTC
Created attachment 18428 [details]
Http Client Sample

If I startup my app on an iPad or iPhone where wifi is off (no LTE is available), my http requests fail as expected. But when I then turn wifi on, they still fail. I have to restart the app to get my requests working again. I validated that other apps work fine after the wifi is toggled on to make sure that the internet connection is working.

I tried to reproduce the issue with one of the Xamarin samples (https://developer.xamarin.com/samples/monotouch/HttpClient/). Indeed I get the same issue here. I only modified the code slightly to allow for subsequent http requests after a failed one.


Steps to reproduce:

    Run the attached version of the http sample app while your device has no internet connection (wifi toggled off)
    Select "http - WebRequest" and submit a few requests by clicking "Issue Http request"
    Observe in the console output that the http requests fail
    Toggle the wifi on. Ensure internet connectivity.
    Submit a few more http requests
    Observe that all requests still fail. This is the issue. If the app is killed and then restarted, everything works again. So it looks like we get in a bad state and do not recover.
    (I tried this on an ipad and an iphone running ios9 and I am using Xamarin Studio 6.1)

Information above is from Oliver Gartner's post: https://forums.xamarin.com/discussion/78923/http-requests-do-not-work-when-wifi-is-toggled-off-and-back-on#latest

Looks like there was another case that was changed to RESOLVED NORESPONSE: https://bugzilla.xamarin.com/show_bug.cgi?id=41514

Since that previous bug was changed to RESOLVED NORESPONSE, I'll provide whatever information is needed to resolve issue on this new bug.

Thanks Xamarin Team
Comment 1 Sebastien Pouliot 2016-11-11 14:39:26 UTC
Bug #41514 was about HttpClient and (native) NSUrlSessionHandler (and other things as well). Your description seems to be using WebRequest (managed).

> So it looks like we get in a bad state and do not recover.

Yes, and the various implementations might behave differently.

@Manuel please confirm the above for all configurations, i.e. WebRequest and all (3) HttpClient handlers. Thanks!
Comment 2 Danny Cabrera 2016-11-11 14:43:14 UTC
Thanks Sebastien. Let me know if you need any additional info.
Comment 3 Manuel de la Peña 2016-11-21 16:33:19 UTC
Hello,

I have taking a look at the sample app and I've got the following conclusions:

WebRequest - Wifi Off -> On

   Http: System.Net.WebException: Error: NameResolutionFailure
   Https: No exception is thrown but the request does not completes.

   When you set the wifi on you get:

   Http: System.Net.WebException: Error: NameResolutionFailure
   Https: No exception is thrown but the request does not complete.

WebRequest - Wifi On -> Off -> On

    Http: Success
    Https: Sucess

    When you turn the Wifi Off:

    Http: System.Net.WebException: Error: ConnectFailure (Network is unreachable)
    Https: No exception is thrown but the request does not completes.

    When you turn the Wifi On again:

    Http: Success
    Https: No exception is thrown but the request does not complete.

NSUrlConnection - Wifi Off -> On

    http: Call failed with The Internet connection appears to be offline.

    Once the wifi is on:

    http: Success

NSUrlConnection - Wifi On -> Off -> On

    http: Success 
   
    Once you switch the wifi off:
   
    http: Call failed with The Internet connection appears to be offline.

    Once the wifi is back on:

    http: Success

HttpClient:

    Managed - Wifi Off -> On
 
        http:  No exception is thrown but the request does not complete.
        https:  No exception is thrown but the request does not complete.

        Once the wifi is back on:

        http:  No exception is thrown but the request does not complete.
        https:  No exception is thrown but the request does not complete.

    Managed - Wifi On -> Off -> On

        http: Success
        https: Success

        Once the wifi is off:

        http:  No exception is thrown but the request does not complete.
        https:   No exception is thrown but the request does not complete.

        Once the wifi is back on:

        http: Success
        https: Success

    CFNetwork - Wifi Off -> On

        http: No exception is thrown but the request does not complete.
        https: No exception is thrown but the request does not complete.

        Once the wifi is back on:

        http: Success
        https: Success

    CFNetwork - Wifi On -> Off -> On

        http: Success
        https: Success

        Once the wifi is off:

        http: No exception is thrown but the request does not complete.
        https: No exception is thrown but the request does not complete.

        Once the wifi is back on:

        http: Success
        https: Success

    NSUrlsSession - Wifi Off -> On

        http: No exception is thrown but the request does not complete.
        https: No exception is thrown but the request does not complete.

        Once the wifi is back on:

        http: Success
        https: Success

    NSUrlsSession - Wifi On -> Off -> On

        http: Succes
        https: Success

        Once the wifi is off:

        http: No exception is thrown but the request does not complete.
        https: No exception is thrown but the request does not complete.

        Once the wifi is back on:

        http: Success
        https: Success

By the looks of it we have an issue in the managed implementations that are not working as expected. Looks like our managed implementation ignores the network status, when the network is not present and we make a web request we get into a state from which we cannot recover BUT if the wifi is on, then goes off and on again, the managed implementations do work. 

ALL the native implementations do work and perform a expected. Please not that I state that the request does not complete, that is due to a timeout in the async.

Test environment:

    Device: iPhone 7 - 10.1.1
            iPhone SE - 10.1.1

    Xamarin: 

=== Xamarin Studio Community ===

Version 6.1.2 (build 44)
Installation UUID: 01060673-5bee-4cf4-a4c2-5e36a18d39a2
Runtime:
	Mono 4.6.2 (mono-4.6.0-branch/08fd525) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406020007

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 8.2 (11764)
Build 8C30a

=== Xamarin.iOS ===

Version: 10.5.0.67 (Xamarin Studio Community)
Hash: 94e47a0
Branch: master
Build date: 2016-11-21 11:03:31+0100

=== Xamarin.Mac ===

Version: 3.1.0.30 (Xamarin Studio Community)

=== Xamarin.Android ===

Version: 7.0.2.37 (Xamarin Studio Community)
Android SDK: /Users/mandel/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)

SDK Tools Version: 25.1.6
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

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

=== Build Information ===

Release ID: 601020044
Git revision: 0ccfcd52b95305ebd5b7eca0d88c1017035910ae
Build date: 2016-10-28 15:12:43-04
Xamarin addins: a39a869d8a78d87bdc6775f696c13a4cc9024501
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.12.1
Darwin MacBook-Pro.local 16.1.0 Darwin Kernel Version 16.1.0
    Thu Oct 13 21:26:57 PDT 2016
    root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Addin Maker 1.3.2
StyleCop Support 1.0.1.9
Manifest.addin 0.0.0.0
Comment 4 Manuel de la Peña 2016-11-21 16:43:27 UTC
Moving the bug to BCL since the native implementations do work. Waiting for @Sebastien input.
Comment 5 Alexandre Pepin 2016-11-22 18:18:00 UTC
We are also experiencing this issue. When starting the application without Internet, the application will never be able to make request even if we get Internet back.
Comment 6 Laurence Lafontaine 2016-12-01 21:02:38 UTC
Hi, this issue is critical for our app. Do you have any idea when it will be fixed?
Comment 7 Brendan Zagaeski (Xamarin Support) 2016-12-05 22:35:52 UTC
## Note to the Xamarin engineering team

Bug 45761 (reported as a regression in Mono) looks possibly related.
Comment 8 Sebastien Pouliot 2016-12-14 23:02:24 UTC
Manuel, can you confirm if the workarounds from bug #45761 works on XI ?

I'm fairly sure this is a duplicate of that bug, but we need to be sure before merging them. Thanks!
Comment 9 Marek Safar 2016-12-21 10:14:32 UTC

*** This bug has been marked as a duplicate of bug 45761 ***
Comment 10 Marek Safar 2017-02-06 15:25:56 UTC
*** Bug 40104 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.