This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 46626 - [CFNetworkHandler] An inexistent hostname causes app crash
Summary: [CFNetworkHandler] An inexistent hostname causes app crash
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: (C9)
Assignee: Rolf Bjarne Kvinge
URL:
Depends on:
Blocks:
 
Reported: 2016-11-09 10:15 UTC by Rolf Bjarne Kvinge
Modified: 2016-12-02 17:52 UTC (History)
2 users (show)

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


Attachments

Description Rolf Bjarne Kvinge 2016-11-09 10:15:24 UTC
Test code:

> try {
> 	HttpClient client = new HttpClient ();
> 	var s = await client.GetStringAsync ("http://doesnotexistasdfasdfasdfasdfasdfasdf.com");
> 	Console.WriteLine (s);
> } catch (Exception e) {
> 	Console.WriteLine (e);
> }

Results in:

> 2016-11-09 11:11:37.998 testapp[50812:37425367] 
> Unhandled Exception:
> System.ArgumentException: Argument passed in is not serializable.
> Parameter name: key
>   at System.Collections.ListDictionaryInternal.Add (System.Object key, System.Object value) [0x0002b] in /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/collections/listdictionaryinternal.cs:145 
>   at CoreFoundation.CFException.FromCFError (System.IntPtr cfErrorHandle, System.Boolean release) [0x00093] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFException.cs:118 
>   at CoreFoundation.CFException.FromCFError (System.IntPtr cfErrorHandle) [0x00000] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFException.cs:99 
>   at CoreFoundation.CFReadStream.GetError () [0x0001e] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFReadStream.cs:61 
>   at System.Net.Http.CFNetworkHandler.HandleErrorEvent (System.Object sender, CoreFoundation.CFStream+StreamEventArgs e) [0x00020] in /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.Net.Http/CFNetworkHandler.cs:248 
>   at CoreFoundation.CFStream.OnErrorEvent (CoreFoundation.CFStream+StreamEventArgs args) [0x0000d] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFStream.cs:427 
>   at CoreFoundation.CFStream.OnCallback (CoreFoundation.CFStreamEventType type) [0x00073] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFStream.cs:466 
>   at CoreFoundation.CFStream.OnCallback (System.IntPtr s, System.nint type, System.IntPtr info) [0x00014] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFStream.cs:449 
>   at (wrapper native-to-managed) CoreFoundation.CFStream:OnCallback (intptr,System.nint,intptr)
> --- End of stack trace from previous location where exception was thrown ---
>   at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
>   at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /work/maccore/master/xamarin-macios/src/UIKit/UIApplication.cs:79 
>   at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /work/maccore/master/xamarin-macios/src/UIKit/UIApplication.cs:63 
>   at AppDelegate.Main (System.String[] args) [0x00008] in /Users/rolf/Projects/TestApp/test-app/AppDelegate.cs:101 
> 2016-11-09 11:11:38.000 testapp[50812:37425367] Unhandled managed exception:
> Argument passed in is not serializable.
> Parameter name: key (System.ArgumentException)
>   at System.Collections.ListDictionaryInternal.Add (System.Object key, System.Object value) [0x0002b] in /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/collections/listdictionaryinternal.cs:145 
>   at CoreFoundation.CFException.FromCFError (System.IntPtr cfErrorHandle, System.Boolean release) [0x00093] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFException.cs:118 
>   at CoreFoundation.CFException.FromCFError (System.IntPtr cfErrorHandle) [0x00000] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFException.cs:99 
>   at CoreFoundation.CFReadStream.GetError () [0x0001e] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFReadStream.cs:61 
>   at System.Net.Http.CFNetworkHandler.HandleErrorEvent (System.Object sender, CoreFoundation.CFStream+StreamEventArgs e) [0x00020] in /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.Net.Http/CFNetworkHandler.cs:248 
>   at CoreFoundation.CFStream.OnErrorEvent (CoreFoundation.CFStream+StreamEventArgs args) [0x0000d] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFStream.cs:427 
>   at CoreFoundation.CFStream.OnCallback (CoreFoundation.CFStreamEventType type) [0x00073] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFStream.cs:466 
>   at CoreFoundation.CFStream.OnCallback (System.IntPtr s, System.nint type, System.IntPtr info) [0x00014] in /work/maccore/master/xamarin-macios/src/CoreFoundation/CFStream.cs:449 
>   at (wrapper native-to-managed) CoreFoundation.CFStream:OnCallback (intptr,System.nint,intptr)
> --- End of stack trace from previous location where exception was thrown ---
>   at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
>   at UIKit.UIAppXamarin.Hosting: Simulated process has exited.
> lication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /work/maccore/master/xamarin-macios/src/UIKit/UIApplication.cs:79 
>   at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /work/maccore/master/xamarin-macios/src/UIKit/UIApplication.cs:63 
>   at AppDelegate.Main (System.String[] args) [0x00008] in /Users/rolf/Projects/TestApp/test-app/AppDelegate.cs:101 
> 2016-11-09 11:11:38.000 testapp[50812:37425367] critical: Stacktrace:
> 
> 2016-11-09 11:11:38.000 testapp[50812:37425367] critical: 
> Native stacktrace:
> 
> 2016-11-09 11:11:38.004 testapp[50812:37425367] critical: 	0   testapp                             0x00000001075dfdad mono_handle_native_sigsegv + 253
> 2016-11-09 11:11:38.004 testapp[50812:37425367] critical: 	1   libsystem_platform.dylib            0x0000000113d72bba _sigtramp + 26
> 2016-11-09 11:11:38.004 testapp[50812:37425367] critical: 	2   ???                                 0x0000000107b7d0d0 0x0 + 4424454352
> 2016-11-09 11:11:38.005 testapp[50812:37425367] critical: 	3   libsystem_c.dylib                   0x0000000113ac9fd7 abort + 129
> 2016-11-09 11:11:38.005 testapp[50812:37425367] critical: 	4   testapp                             0x000000010776ce7f xamarin_unhandled_exception_handler + 47
> 2016-11-09 11:11:38.005 testapp[50812:37425367] critical: 	5   testapp                             0x000000010763b62b mono_invoke_unhandled_exception_hook + 139
> 2016-11-09 11:11:38.005 testapp[50812:37425367] critical: 	6   testapp                             0x00000001075dfb0f mono_handle_exception_internal + 5135
> 2016-11-09 11:11:38.006 testapp[50812:37425367] critical: 	7   testapp                             0x00000001075de6f8 mono_handle_exception + 24
> 2016-11-09 11:11:38.006 testapp[50812:37425367] critical: 	8   testapp                             0x00000001075595bf mono_amd64_throw_exception + 143
> 2016-11-09 11:11:38.006 testapp[50812:37425367] critical: 	9   ???                                 0x00000001275059e7 0x0 + 4954544615
> 2016-11-09 11:11:38.006 testapp[50812:37425367] critical: 	10  testapp                             0x000000010776ca77 xamarin_process_managed_exception_gchandle + 55
> 2016-11-09 11:11:38.006 testapp[50812:37425367] critical: 	11  testapp                             0x000000010776ca33 xamarin_ftnptr_exception_handler + 19
> 2016-11-09 11:11:38.007 testapp[50812:37425367] critical: 	12  ???                                 0x000000012ae01227 0x0 + 5014295079
> 2016-11-09 11:11:38.007 testapp[50812:37425367] critical: 	13  CoreFoundation                      0x0000000112810694 _signalEventSync + 228
> 2016-11-09 11:11:38.007 testapp[50812:37425367] critical: 	14  CoreFoundation                      0x00000001128233d6 _cfstream_solo_signalEventSync + 246
> 2016-11-09 11:11:38.007 testapp[50812:37425367] critical: 	15  CoreFoundation                      0x000000011280e5a2 _CFStreamSignalEvent + 466
> 2016-11-09 11:11:38.007 testapp[50812:37425367] critical: 	16  CFNetwork                           0x00000001122633fb _ZN14HTTPReadStream11streamEventEm + 257
> 2016-11-09 11:11:38.008 testapp[50812:37425367] critical: 	17  CoreFoundation                      0x0000000112810694 _signalEventSync + 228
> 2016-11-09 11:11:38.008 testapp[50812:37425367] critical: 	18  CoreFoundation                      0x0000000112823f5c _cfstream_shared_signalEventSync + 460
> 2016-11-09 11:11:38.008 testapp[50812:37425367] critical: 	19  CoreFoundation                      0x00000001127f0311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
> 2016-11-09 11:11:38.008 testapp[50812:37425367] critical: 	20  CoreFoundation                      0x00000001127d559c __CFRunLoopDoSources0 + 556
> 2016-11-09 11:11:38.008 testapp[50812:37425367] critical: 	21  CoreFoundation                      0x00000001127d4a86 __CFRunLoopRun + 918
> 2016-11-09 11:11:38.009 testapp[50812:37425367] critical: 	22  CoreFoundation                      0x00000001127d4494 CFRunLoopRunSpecific + 420
> 2016-11-09 11:11:38.009 testapp[50812:37425367] critical: 	23  GraphicsServices                    0x000000011344fa6f GSEventRunModal + 161
> 2016-11-09 11:11:38.009 testapp[50812:37425367] critical: 	24  UIKit                               0x0000000108d5d964 UIApplicationMain + 159
> 2016-11-09 11:11:38.009 testapp[50812:37425367] critical: 	25  ???                                 0x0000000129f621ec 0x0 + 4998963692
> 2016-11-09 11:11:38.009 testapp[50812:37425367] critical: 	26  ???                                 0x0000000129f61e2d 0x0 + 4998962733
> 2016-11-09 11:11:38.010 testapp[50812:37425367] critical: 
> =================================================================
> Got a SIGABRT while executing native code. This usually indicates
> a fatal error in the mono runtime or one of the native libraries 
> used by your application.
> =================================================================
> 

The problem is that an exception occurs when we try to construct a managed CFException object from a CFError, and since this happens on a background thread where there are no catch handlers, it ends up terminating the app.
Comment 1 Rolf Bjarne Kvinge 2016-11-09 13:23:05 UTC
PR: https://github.com/xamarin/xamarin-macios/pull/1144

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