Bug 6309 - NetworkReachability.TryGetFlags hangs application in simulator in Mountain Lion
Summary: NetworkReachability.TryGetFlags hangs application in simulator in Mountain Lion
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
: 6364 6477 ()
Depends on:
Blocks:
 
Reported: 2012-07-27 14:56 UTC by JohanO
Modified: 2012-10-24 19:40 UTC (History)
18 users (show)

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


Attachments
stack trace from NetworkReachability.TryGetFlags() in simluator on Mtn Lion (10.56 KB, text/plain)
2012-08-07 17:31 UTC, Scott Blomquist (sblom)
Details


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:
Status:
RESOLVED FIXED

Description JohanO 2012-07-27 14:56:23 UTC
Guys this is a new one. This is from Miguel's code and we're using it to see if there's network availability. Calling this method with "www.google.com" hangs our application in the simulator. Also, InvokeOnMainThread calls seems to have strange behavior but more on that in a separate bug.

// Is the host reachable with the current network configuration
	public static bool IsHostReachable (string host)
	{
		if (host == null || host.Length == 0)
			return false;

		using (var r = new NetworkReachability (host))
		{
			NetworkReachabilityFlags flags;


			if (r.TryGetFlags (out flags)){
				return IsReachableWithoutRequiringConnection (flags);
			}
		}
		return false;
	}
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-08-07 10:03:52 UTC
I just tried this and I couldn't get it to hang.

Can you attach gdb when it hangs:

gdb program <pid>

You can find the pid in the application output pad when the app starts up. Then after gdb has attached, do:

(gdb) thread apply all backtrace

and you'll get a stack trace for each thread. Please save all the output to a file and attach it here.
Comment 2 Scott Blomquist (sblom) 2012-08-07 17:31:53 UTC
Created attachment 2321 [details]
stack trace from NetworkReachability.TryGetFlags() in simluator on Mtn Lion

I reliably hang in the simulator on the third line below:

NetworkReachabilityFlags flags;
NetworkReachability reachable = new NetworkReachability("itunes.apple.com");
reachable.TryGetFlags(out flags);
Comment 3 Scott Blomquist (sblom) 2012-08-07 19:08:26 UTC
I reliably hang on this third line, also:

            NetworkReachability reachability = new NetworkReachability("itunes.apple.com");
            reachability.SetCallback(ReachabilityChanged);
            reachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
Comment 4 Rolf Bjarne Kvinge [MSFT] 2012-08-08 07:02:56 UTC
I still can't reproduce any hangs. From the stack trace it doesn't look like it's MonoTouch related, it's hanging in native code, waiting something (network related probably) on another thread to finish.

Do you get the same behavior on a device? And can you try the ObjectiveC sample: http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007324-Intro-DontLinkElementID_2 to see if that hangs too?
Comment 5 Scott Blomquist (sblom) 2012-08-08 12:16:03 UTC
Works fine for me on a device. And I just tried the Apple Reachability sample which works fine on the simulator as well as on a device.

Admittedly, the app's flow is ever so slightly different--I'll try to make it a more direct comparison.

But the key line that I would've predicted to hang looks substantially identical:

NetworkStatus netStatus = [curReach currentReachabilityStatus];

Completely wild throw: Is it possible that somehow the soft debugger is the network traffic that's getting in its way?


More notes:
I just wrote my first MonoTouch reachabitity code this week, so I can't point to a particular software update that might be correlated here. For all I know this could've been happening since the beginning of time. Would definitely be interesting to get Johan's timeline.

I'm building for simulator 5.1, but running on a 5.0 device. I'll try it on a 5.1 device this afternoon. I'll also have a coworker that hasn't yet installed Mtn Lion try my code on his simulator.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2012-08-08 12:32:36 UTC
You can easily test if the soft debugger is interfering by running the app in the simulator without it (tap on it instead of running with MonoDevelop).
Comment 7 Scott Blomquist (sblom) 2012-08-08 15:28:55 UTC
Ruled out the soft debugger using your steps, Rolf.

More data: I was wondering if it was complex interaction in my app that was causing this problem, so I built the reachability sample from monotouch-samples. It hangs.

I admit that there's no incontrovertible evidence that this is a MonoTouch problem, but since Apple's trivial sample works and Xamarin's trivial sample (which is a port of Apple's, it appears) doesn't, I can't imagine Apple support is going to take ownership of this issue without some more evidence.

Would it help for me to give you screen sharing access to my machine?
Comment 8 Rolf Bjarne Kvinge [MSFT] 2012-08-08 18:29:48 UTC
*** Bug 6477 has been marked as a duplicate of this bug. ***
Comment 9 Rolf Bjarne Kvinge [MSFT] 2012-08-08 18:31:14 UTC
Sebastién, can you try to reproduce this? It works perfectly for me :|
Comment 10 Robert Kozak 2012-08-08 19:15:34 UTC
I would like to chime in and saying this is happening to me too
Comment 11 Sebastien Pouliot 2012-08-08 19:17:42 UTC
I'm still running on SL and Lion. No new toys (yet) for me. c.c. PJ
Comment 12 Robert Kozak 2012-08-08 19:19:53 UTC
Since I updated to Mountain Lion I can't get reachability to work with the
simulator. It hangs on  NetworkReachability.TryGetFlags(). Also still does the
same thing if I launch directly thru the simulator and bypassing MonoDevelop. 

Same code works fine on the device.
Comment 13 Bo Kingo Damgaard 2012-08-14 08:52:33 UTC
I also have a hang problem with the simulator on Mountain Lion on the reachablity.Schedule line, and it has work before ML. Could it be related to the removal om ios4 simulator? I can't say for sure if its was working with ios5 simulator before ML
Comment 14 René Ruppert 2012-08-14 09:31:07 UTC
It did work with iOS 5 simulator.
Comment 15 Stewart Simpson 2012-08-15 04:23:17 UTC
This is also happening for me on the iOS 5 simulator. I have just upgraded to Mountain Lion and my application hangs on NetworkReachability.TryGetFlags(). I can debug on an actual device fine.
Comment 16 Andy 2012-08-19 10:07:03 UTC
I am also experiencing this behavior on Mountain Lion.  I have also completely uninstalled monotouh/monodevelop/mono and reinstalled them.  I am running XCode 4.4 and using iPad Simulator 5.1 (I do not have a option for 5.0).  Below is the code, hanging on the third line.  The status of the bug is NEEDINFO, is there any additional information I can try to provide?

defaultRouteReachability = new NetworkReachability ("http://www.google.com");
defaultRouteReachability.SetCallback (OnChange);
defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
Comment 18 Sebastien Pouliot 2012-08-22 09:23:11 UTC
Can everyone (who has not done so before) affected by this issue please state which version of Xcode they are using ?

Even better go the MonoDevelop menu, "About MonoDevelop", "Version Information" and copy/paste the information back to this bug report.

Also if you have access to other Xcode versions (e.g. parallel installations) and you could try changing your SDK location (MonoDevelop's preferences) this might confirm something we suspect. Thanks!
Comment 19 Bo Kingo Damgaard 2012-08-22 09:25:14 UTC
I have this


MonoDevelop 3.0.3.5
Installation UUID: ec0ce492-ad73-4567-885f-be02fca160ee
Runtime:
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.4.1 (1488)
	 Build 4F1003
Monotouch: 5.2.13
Mono for Android not installed
Build information:
	Release ID: 30003005
	Git revision: 3d53e1366933298a3fe0cdc6d0f7d00c9916564c-dirty
	Build date: 2012-07-27 19:06:34+0000
	Xamarin addins: 73ecde7c48d943adb6e33d511d3cf0661d006801
Operating System:
	Mac OS X 10.8.0
	Darwin Bo-Kingo-Madsens-MacBook-Pro-2.local 12.0.0 Darwin Kernel Version 12.0.0
	    Sun Jun 24 23:00:16 PDT 2012
	    root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
Comment 20 Stewart Simpson 2012-08-22 10:18:50 UTC
Here is my setup info

MonoDevelop 3.0.3.5
Installation UUID: 951deb7c-4914-4674-b78c-8393ab077f08
Runtime:
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.4.1 (1488)
	 Build 4F1003
Monotouch: 5.2.13
Mono for Android not installed
Build information:
	Release ID: 30003005
	Git revision: 3d53e1366933298a3fe0cdc6d0f7d00c9916564c-dirty
	Build date: 2012-07-27 19:06:34+0000
	Xamarin addins: 73ecde7c48d943adb6e33d511d3cf0661d006801
Operating System:
	Mac OS X 10.8.0
	Darwin STEWART-SIMPSONS-MPB.local 12.0.0 Darwin Kernel Version 12.0.0
	    Sun Jun 24 23:00:16 PDT 2012
	    root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
Comment 22 René Ruppert 2012-08-22 13:06:35 UTC
MonoDevelop 3.0.3.5
Installation UUID: 96474f8f-0d92-4fc7-866c-a6174ca888b0
Runtime:
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.4.1 (1488)
	 Build 4F1003
Monotouch: 5.2.13
Mono for Android not installed
Build information:
	Release ID: 30003005
	Git revision: 3d53e1366933298a3fe0cdc6d0f7d00c9916564c-dirty
	Build date: 2012-07-27 19:06:34+0000
	Xamarin addins: 73ecde7c48d943adb6e33d511d3cf0661d006801
Operating System:
	Mac OS X 10.8.0
	Darwin imac.fritz.box 12.0.0 Darwin Kernel Version 12.0.0
	    Sun Jun 24 23:00:16 PDT 2012
	    root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
Comment 23 John 2012-08-22 19:47:28 UTC
My info below:

MonoDevelop 3.0.3.5
Installation UUID: 2a7fac5b-4202-4cc4-b5ec-abe6dc061ba3
Runtime:
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.4.1 (1488)
	 Build 4F1003
Monotouch: 5.2.13
Mono for Android not installed
Build information:
	Release ID: 30003005
	Git revision: 3d53e1366933298a3fe0cdc6d0f7d00c9916564c-dirty
	Build date: 2012-07-27 19:06:34+0000
	Xamarin addins: 73ecde7c48d943adb6e33d511d3cf0661d006801
Operating System:
	Mac OS X 10.8.0
	Darwin John-Downss-MacBook-Pro.local 12.0.0 Darwin Kernel Version 12.0.0
	    Sun Jun 24 23:00:16 PDT 2012
	    root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64


I also have Xcode 4.5 DP4 installed. I tried switching to this version of the SDK in MonoDevelop preferences and had the same issue with the network reachability test hanging.
Comment 24 PJ 2012-08-22 20:28:13 UTC
John - any chance you attempted the test with Xcode 4.5 DP4 without restarting MD?

MonoDevelop only saves its preferences on exiting and loads them on opening, so you may still have been using Xcode 4.4.1.

Thank you for your information!
Comment 25 Andy 2012-08-22 20:38:27 UTC
Just to add additional informaiton, I installed Monotouch BETA 5.3.5, and the issue is fixed there.  I noticed in the release notes there was some work done on NetworkReachability so I don't know if that can help identify the issue. There are other quirks in the BETA so I'm not advocating updating, just FYI.
Comment 26 John 2012-08-22 20:47:05 UTC
PJ - good catch. I made the change, restarted MD, and here is the version information from MD:


MonoDevelop 3.0.3.5
Installation UUID: 2a7fac5b-4202-4cc4-b5ec-abe6dc061ba3
Runtime:
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.5 (1828)
	 Build 4G144l
Monotouch: 5.2.13
Mono for Android not installed
Build information:
	Release ID: 30003005
	Git revision: 3d53e1366933298a3fe0cdc6d0f7d00c9916564c-dirty
	Build date: 2012-07-27 19:06:34+0000
	Xamarin addins: 73ecde7c48d943adb6e33d511d3cf0661d006801
Operating System:
	Mac OS X 10.8.0
	Darwin John-Downss-MacBook-Pro.local 12.0.0 Darwin Kernel Version 12.0.0
	    Sun Jun 24 23:00:16 PDT 2012
	    root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64


When I ran my app, the iOS 6 simulator started (I just realised that previously it was starting the iOS 5.1 simulator).

I then rebuilt my app to remove the commented-out reachability check so I could do a proper test. However, now I get an 'unexpected error' when building, error MT0000. Here's the exception from the build info with the relevant section:

Compiling to native code
/Developer/MonoTouch/usr/bin/mtouch -sdkroot "/Applications/Xcode45-DP4.app/Contents/Developer" -v --nomanifest --nosign -sim "/Users/john/Projects/Collage/iOS/bin/iPhoneSimulator/Debug/Collage.app" -r "/Users/john/Projects/Collage/Collage.Network/bin/iPhoneSimulator/Debug/Collage.Network.dll" -r "/Users/john/Projects/Collage/Collage.Network.Client/bin/iPhoneSimulator/Debug/Collage.Network.Client.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Web.Services.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/MonoTouch.Dialog-1.dll" -debug -nolink -sdk "6.0" -targetver "5.0" --armv7 "/Users/john/Projects/Collage/iOS/bin/iPhoneSimulator/Debug/Collage.exe"
MonoTouch version 5.2.13 using framework: /Applications/Xcode45-DP4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk
error MT0000: Unexpected error - Please fill a bug report at http://bugzilla.xamarin.com
System.Xml.XmlException: Invalid data ---> System.Text.DecoderFallbackException: Exception of type 'System.Text.DecoderFallbackException' was thrown.
  at System.Text.DecoderExceptionFallbackBuffer.Fallback (System.Byte[] bytesUnknown, Int32 index) [0x00000] in <filename unknown>:0 
  at System.Text.UTF8Encoding.Fallback (System.Object provider, System.Text.DecoderFallbackBuffer& buffer, System.Byte[]& bufferArg, System.Byte* bytes, Int64 byteIndex, UInt32 size, System.Char* chars, System.Int32& charIndex) [0x00000] in <filename unknown>:0 
  at System.Text.UTF8Encoding.InternalGetChars (System.Byte* bytes, Int32 byteCount, System.Char* chars, Int32 charCount, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) [0x00000] in <filename unknown>:0 
  at System.Text.UTF8Encoding.InternalGetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) [0x00000] in <filename unknown>:0 
  at System.Text.UTF8Encoding+UTF8Decoder.GetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex) [0x00000] in <filename unknown>:0 
  at System.Xml.NonBlockingStreamReader.ReadBuffer () [0x00000] in <filename unknown>:0 
  at System.Xml.NonBlockingStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Xml.XmlStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0 
  at Mono.Xml2.XmlTextReader.ReadTextReader (Int32 remained) [0x00000] in <filename unknown>:0 
  at Mono.Xml2.XmlTextReader.PeekChar () [0x00000] in <filename unknown>:0 
  at Mono.Xml2.XmlTextReader.ReadContent () [0x00000] in <filename unknown>:0 
  at Mono.Xml2.XmlTextReader.Read () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlTextReader.Read () [0x00000] in <filename unknown>:0 
  at Mono.Xml.EntityResolvingXmlReader.Read () [0x00000] in <filename unknown>:0 
  at Mono.Xml.DTDValidatingReader.ReadContent () [0x00000] in <filename unknown>:0 
  at Mono.Xml.DTDValidatingReader.Read () [0x00000] in <filename unknown>:0 
  at Mono.Xml.Schema.XsdValidatingReader.Read () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlValidatingReader.Read () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.Load (System.String filename) [0x00000] in <filename unknown>:0 
  at MTouch.Main2 (System.String[] args) [0x00000] in <filename unknown>:0 
  at MTouch.Main (System.String[] args) [0x00000] in <filename unknown>:0 


I tried restarting MD, and doing a clean and then build solution, but still getting the same exception.

I don't really want to upgrade MD at the moment to see if that fixes this as I'm doing some work on a real app... but if there's anything else I can to help let me know.
Comment 28 Sebastien Pouliot 2012-08-22 20:58:24 UTC
John, that's a known (and fixed in the latest MD) issue. Thanks for trying it (and do not upgrade just to try this out).

Andy, please fill bug reports if you have any unreported issue(s) with 5.3.5
(we're close to releasing 5.4).
Comment 30 John 2012-09-06 21:55:21 UTC
Just wanted to advise that, on my machine at least, this issue is no longer happening with MonoTouch 5.4 and MonoDevelop 3.0.4.6. My version info is below. So hopefully the issue is gone :)


MonoDevelop 3.0.4.6
Installation UUID: 2a7fac5b-4202-4cc4-b5ec-abe6dc061ba3
Runtime:
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.4.1 (1488)
	 Build 4F1003
Monotouch: 5.4.0
Mono for Android: Not Installed

Build information:
	Release ID: 30004006
	Git revision: 0cf43d761292de23383842f385fcba4645b03854
	Build date: 2012-09-06 21:36:19+0000
	Xamarin addins: 75a3c9ec1a014eebf0f8346280ba8d7ad9629d3d-dirty
Operating System:
	Mac OS X 10.8.1
	Darwin John-Downss-MacBook-Pro.local 12.1.0 Darwin Kernel Version 12.1.0
	    Tue Aug 14 13:29:55 PDT 2012
	    root:xnu-2050.9.2~1/RELEASE_X86_64 x86_64
Comment 31 Sebastien Pouliot 2012-09-13 11:20:01 UTC
The issue is fixed in 5.4.0 (stable)
Comment 32 Rolf Bjarne Kvinge [MSFT] 2012-10-24 19:40:17 UTC
*** Bug 6364 has been marked as a duplicate of this bug. ***