Bug 20561 - cellular data to Wifi my app losses the connectivity to web service
Summary: cellular data to Wifi my app losses the connectivity to web service
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: master
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Martin Baulig
Depends on:
Reported: 2014-06-12 15:18 UTC by Suriya guru seelan
Modified: 2014-07-31 07:10 UTC (History)
6 users (show)

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

Error While adding environment Variable (118.21 KB, image/jpeg)
2014-07-22 06:50 UTC, Suriya guru seelan

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 Suriya guru seelan 2014-06-12 15:18:55 UTC
I am using ASMX services to get data from the server, On the go if i switch the connection 
from Wifi to a cellular data connection or  cellular data to Wifi my app losses the connectivity to web service and again i have to kill the app. Again it is working fine.

Can you please suggest what i have to do when switching from  Wifi to a cellular data connection or  cellular data to Wifi.
Comment 2 Naren 2014-07-14 11:14:39 UTC
Any updates on this item, Thanks
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-07-21 09:28:29 UTC
Can you try adding the following code as the first line the the Main method, and see if something changes:

			System.Net.ServicePointManager.MaxServicePointIdleTime = 1;
			Environment.SetEnvironmentVariable ("MONO_TLS_SESSION_CACHE_TIMEOUT", "0");
Comment 4 Suriya guru seelan 2014-07-21 15:27:21 UTC
Not able to add   Environment.SetEnvironmentVariable ("MONO_TLS_SESSION_CACHE_TIMEOUT", "0"); through Code.

Added via project=>options=>Run=>GeneralEnvironmentVariable

But still i am having issue while switching from WIFI to 3G
Comment 5 Rolf Bjarne Kvinge [MSFT] 2014-07-21 15:29:58 UTC
Why were you not able to set MONO_TLS_SESSION_CACHE_TIMEOUT through code?

Did you set MaxServicePointIdleTime to 1 as well?
Comment 6 Suriya guru seelan 2014-07-21 15:35:28 UTC
I added System.Net.ServicePointManager.MaxServicePointIdleTime = 1; as my firs line inside the main method of Main.CS

But Environment.SetEnvironmentVariable shows method not available only getEnvironmentVariable variable is available.
Comment 7 Rolf Bjarne Kvinge [MSFT] 2014-07-22 06:05:45 UTC
Martin, do you have an iOS device with a sim card? If so, could you have a look at this?
Comment 8 Suriya guru seelan 2014-07-22 06:50:58 UTC
Created attachment 7442 [details]
Error While adding environment Variable

Error While adding environment Variable..
Comment 11 Miguel de Icaza [MSFT] 2014-07-25 15:02:51 UTC
Hey guys,

Just want to set things straight here.

When you switch from a radio connection to a WiFi connection you are changing your IP address, and when that happens, existing TCP connections are reset.

So this is entirely expected: switching networks will reset TCP connections, and by extension, it will reset HTTP connections.

The workaround is to detect whenever this connection closes, and re-establish the connection.

The original report does not really describe what "loses connectivity" is
Comment 12 Miguel de Icaza [MSFT] 2014-07-25 15:11:47 UTC
iOS 7 is able to support the transition in certain networks that support TCP multipath:

Comment 13 Naren 2014-07-25 15:35:42 UTC
The sample we created and provided to your team, they were also able to replicate the issue with that and then it was posted for further analysis to the iOS team.

I would appreciate, if you can review that sample and test the scenario I posted below and provide us guidance.

The issue we are facing is, if we were outside and start using the application in 3G and come inside a wifi network, it continue to work.

if the application is started with wifi connection and when we go out on to 3G connection - it stops working. In this case we close and restart it is not working.

Even if we close the webservice object and create a new webservice object it is not working.

is there anything we need to do extra.

previously programmer from xamarin, suggested to set some environment variables, but that we are not able to even compile because SET is not allowed on those (we got compilation error).

Same issue with android also.

if needed we can send you the test application and the screenshot of errors again.

Comment 14 Suriya guru seelan 2014-07-29 07:19:22 UTC
    I am getting the following exception and Crash when i used the 

System.Net.ServicePointManager.MaxServicePointIdleTime = 1; as the first line of the main method.

Unhandled Exception:
0   ActiveResponse                      0x00b6149d mono_handle_exception_internal + 2484
1   ActiveResponse                      0x00b60ae3 mono_handle_exception + 10
2   ActiveResponse                      0x00b5b2d5 mono_arm_throw_exception + 104
3   ActiveResponse                      0x00352c64 throw_exception + 68
at System.Net.ServicePoint.CheckAvailableForRecycling (System.DateTime&) [0x0010b] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/ServicePoint.cs:317
at System.Net.ServicePoint.IdleTimerCallback (object) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/ServicePoint.cs:338
at System.Threading.Timer/Scheduler.TimerCB (object) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Timer.cs:317
at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c8>
8   ActiveResponse                      0x00b6d101 mono_jit_runtime_invoke + 1196
9   ActiveResponse                      0x00bac0e5 mono_runtime_invoke + 88
10  ActiveResponse                      0x00baf88b mono_runtime_delegate_invoke + 62
11  ActiveResponse                      0x00bdafbb async_invoke_thread + 1954
12  ActiveResponse                      0x00be0df5 start_wrapper + 244
13  ActiveResponse                      0x00bf34d3 inner_start_thread + 158
14  libsystem_pthread.dylib             0x397a5919 <redacted> + 140
15  libsystem_pthread.dylib             0x397a588b _pthread_start + 102
16  libsystem_pthread.dylib             0x397a3aa4 thread_start + 8

Comment 15 Martin Baulig 2014-07-29 09:14:20 UTC
What happens if you put the device into aircraft mode and turn the 3G back on after about three minutes?  If that fixes it, then what happens if you activate and immediately deactivate aircraft mode?

Can you also try to simply connect to the web service even if that NetworkStatus check returns false.
Comment 16 Martin Baulig 2014-07-29 09:14:51 UTC
The crash from comment #14 looks like a bug that's already been fixed.
Comment 17 Suriya guru seelan 2014-07-31 07:10:38 UTC
Dear All,

              Reviewing this article  https://bugzilla.xamarin.com/show_bug.cgi?id=15152 and correlating the same with our project , we came to know,because of this server ip switching, our application is losing 
connectivity and never able to connect to host and not working.

 i.e.  DNS not refreshing.

So it not an issue and we resolve it for our server side.

Thanks for your kind help.

we can close this bug.