This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 52279 - NSUrlSessionHandler Gets SIGSEGV when sending POST via SendAsync
Summary: NSUrlSessionHandler Gets SIGSEGV when sending POST via SendAsync
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General (show other bugs)
Version: XI 10.4 (C9)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.1
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2017-02-03 14:25 UTC by leankitryan
Modified: 2017-03-22 12:00 UTC (History)
6 users (show)

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


Attachments
NSInputStream example app. (68.53 KB, application/zip)
2017-02-15 17:38 UTC, Manuel de la Peña
Details
Error test app (26.11 KB, application/zip)
2017-02-17 15:57 UTC, Manuel de la Peña
Details
Bug_52279 Ide Logs and Build output Stacktrace (492.91 KB, application/x-zip-compressed)
2017-03-22 11:59 UTC, Mohak Barokar
Details

Description leankitryan 2017-02-03 14:25:35 UTC
# Steps to reproduce
1. Create a new iOS Single View App
2. Change the project build options - HttpClient implementation to to NSUrlSession, Linker behavior to Link Framework SDKs only, Supported Architecture to i386
3. Override ViewController ViewDidLoad as follows:

		public override async void ViewDidLoad()
		{
			base.ViewDidLoad();

			var request = new HttpRequestMessage(HttpMethod.Post, new Uri("https://api.segment.io/v1/import")) {
				Content = new StringContent("{}", Encoding.UTF8, "application/json")
			};
			var client = new HttpClient();
			await client.SendAsync(request);
		}
4. Run the application on an iOS simulator. I have tried iPhone 7 10.2, iPhone 6 10.2, iPhone 6 10.0, iPhone 6 9.3, and iPad Air 2 10.2.

# Expected behavior
App does not crash

# Actual behavior
App crashes

Switching to stable channel, changing the architecture, or disabling linking all seem to prevent the crash.

# Supplemental info (logs, images, videos)

critical: Stacktrace:
critical:   at <unknown> <0xffffffff>
critical:   at (wrapper managed-to-native) object.wrapper_native_0x2fbb49c (intptr,CoreFoundation.CFStreamEventType,intptr) <0x00012>
critical:   at (wrapper delegate-invoke) <Module>.invoke_void_intptr_CFStreamEventType_intptr (intptr,CoreFoundation.CFStreamEventType,intptr) [0x00061] in <cd42a4eae6c543289ffa8a0268de6442>:0
critical:   at CoreFoundation.CFStreamClientContext.CFReadStreamRef_InvokeCallback (intptr,intptr,CoreFoundation.CFStreamEventType,intptr) [0x00000] in /Users/builder/data/lanes/3985/2bcf787f/source/xamarin-macios/src/CoreFoundation/CFStream.cs:138
critical:   at CoreFoundation.CFStreamClientContext.Invoke (intptr,intptr,CoreFoundation.CFStreamEventType) [0x00011] in /Users/builder/data/lanes/3985/2bcf787f/source/xamarin-macios/src/CoreFoundation/CFStream.cs:106
critical:   at Foundation.NSInputStream.Notify (CoreFoundation.CFStreamEventType) [0x00010] in /Users/builder/data/lanes/3985/2bcf787f/source/xamarin-macios/src/Foundation/NSInputStream.cs:116
critical:   at System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Schedule (Foundation.NSRunLoop,string) [0x0002e] in /Users/builder/data/lanes/3985/2bcf787f/source/xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:642
critical:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) [0x0005b] in <e7ba779864604c5896850f13f0b1bd2e>:0
critical: 
	Native stacktrace:
critical: 
	=================================================================
	Got a SIGSEGV while executing native code. This usually indicates
	a fatal error in the mono runtime or one of the native libraries 
	used by your application.
	=================================================================

# Test environment (full version information)

Xamarin Studio Professional
Version 6.2 (build 1798)
Installation UUID: 605daac9-8c37-4142-8ffa-8f712a557af8
Runtime:
	Mono 4.8.0 (mono-4.8.0-branch/084f912) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000478

NuGet
Version: 3.5.0.0

Xamarin.Profiler
'/Applications/Xamarin Profiler.app' not found

Apple Developer Tools
Xcode 8.2.1 (11766.1)
Build 8C1002

Xamarin.iOS
Version: 10.4.0.97 (Visual Studio Professional)
Hash: 2bcf787
Branch: cycle9
Build date: 2017-01-25 12:40:52-0500

Xamarin.Mac
Not Installed

Xamarin.Android
Version: 7.1.0.30 (Visual Studio Professional)
Android SDK: /Users/ryan/Library/Developer/Xamarin/android-sdk-mac_x86
	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)
		4.4.87 (API level 20)
		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_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, 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

Xamarin Inspector
Not Installed

Xamarin Inspector
Version: 0.8.0.0
Hash: dc081aa
Branch: master
Build date: Tue Apr 26 23:07:44 UTC 2016

Build Information
Release ID: 602001798
Git revision: 79fea1cb975eace20d5316687ebb9ff687b51451
Build date: 2017-01-27 07:34:26-05
Xamarin addins: 8e37b5263f1583e25ed2eda77f84829dfcf42759
Build lane: monodevelop-lion-cycle9

Operating System
Mac OS X 10.12.3
Darwin 16.4.0 Darwin Kernel Version 16.4.0
    Thu Dec 22 22:53:21 PST 2016
    root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

Enabled user installed addins
NuGet Package Explorer 0.1
NuGet Package Management Extensions 0.12
Redth's Addins 1.0.4
Xamarin Inspector 0.8.0.0
Comment 1 Manuel de la Peña 2017-02-08 18:16:46 UTC
I was indeed able to reproduce it, I've got a PR I'm working on with a fix.
Comment 2 Manuel de la Peña 2017-02-13 11:43:49 UTC
Just to provide some extra information, when dealing with the notification that data was received we get the following:

2017-02-13 12:30:58.023 HttpClientTest[3112:47178902] Xamarin.iOS: Debugger loaded with custom transport (fd: 4)
2017-02-13 12:30:58.024 HttpClientTest[3112:47178911] Xamarin.iOS: Established connection with the IDE (fd: 6)
2017-02-13 12:30:58.025 HttpClientTest[3112:47178911] Xamarin.iOS: Processing: 'start profiler: no'
2017-02-13 12:30:58.025 HttpClientTest[3112:47178902] Xamarin.iOS: Profiler not loaded (disabled)
2017-02-13 12:30:58.046 HttpClientTest[3112:47178902] Xamarin.iOS: Added dllmap for objc_msgSend
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/EFEE69F7-A317-4958-87DE-68DD26CD2648/HttpClientTest.app/Xamarin.iOS.dll
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/EFEE69F7-A317-4958-87DE-68DD26CD2648/HttpClientTest.app/System.dll
Thread started:  #2
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/EFEE69F7-A317-4958-87DE-68DD26CD2648/HttpClientTest.app/HttpClientTest.exe
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/EFEE69F7-A317-4958-87DE-68DD26CD2648/HttpClientTest.app/System.Net.Http.dll
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/EFEE69F7-A317-4958-87DE-68DD26CD2648/HttpClientTest.app/System.Core.dll
Resolved pending breakpoint at 'ViewController.cs:23,1' to void HttpClientTest.ViewController.<ViewDidLoad>c__async0.MoveNext () [0x00063].
Thread started:  #4
Thread started:  #5
Thread started:  #6
2017-02-13 12:31:01.748 HttpClientTest[3112:47179516] Notifying!!!!
2017-02-13 12:31:01.749 HttpClientTest[3112:47179516] critical: Stacktrace:

2017-02-13 12:31:01.749 HttpClientTest[3112:47179516] critical:   at <unknown> <0xffffffff>
2017-02-13 12:31:01.749 HttpClientTest[3112:47179516] critical:   at (wrapper managed-to-native) object.wrapper_native_0x2b6249c (intptr,CoreFoundation.CFStreamEventType,intptr) <0x00012>
2017-02-13 12:31:01.750 HttpClientTest[3112:47179516] critical:   at (wrapper delegate-invoke) <Module>.invoke_void_intptr_CFStreamEventType_intptr (intptr,CoreFoundation.CFStreamEventType,intptr) [0x00061] in <fce54f24b1e3468fb3b4130c39c10556>:0
2017-02-13 12:31:01.750 HttpClientTest[3112:47179516] critical:   at CoreFoundation.CFStreamClientContext.CFReadStreamRef_InvokeCallback (intptr,intptr,CoreFoundation.CFStreamEventType,intptr) [0x00000] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/CoreFoundation/CFStream.cs:138
2017-02-13 12:31:01.750 HttpClientTest[3112:47179516] critical:   at CoreFoundation.CFStreamClientContext.Invoke (intptr,intptr,CoreFoundation.CFStreamEventType) [0x00011] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/CoreFoundation/CFStream.cs:106
2017-02-13 12:31:01.750 HttpClientTest[3112:47179516] critical:   at Foundation.NSInputStream.Notify (CoreFoundation.CFStreamEventType) [0x00010] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/Foundation/NSInputStream.cs:116
2017-02-13 12:31:01.751 HttpClientTest[3112:47179516] critical:   at System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Schedule (Foundation.NSRunLoop,string) [0x00038] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:643
2017-02-13 12:31:01.751 HttpClientTest[3112:47179516] critical:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) [0x0005b] in <2e7cce17861e41f4abc1fa7aa342d50e>:0
2017-02-13 12:31:01.751 HttpClientTest[3112:47179516] critical: 
Native stacktrace:

2017-02-13 12:31:01.753 HttpClientTest[3112:47179516] critical: 	0   libmonosgen-2.0.dylib               0x0356c54d mono_handle_native_sigsegv + 317
2017-02-13 12:31:01.754 HttpClientTest[3112:47179516] critical: 	1   libmonosgen-2.0.dylib               0x034b1803 mono_sigsegv_signal_handler + 323
2017-02-13 12:31:01.754 HttpClientTest[3112:47179516] critical: 	2   libsystem_platform.dylib            0x04af6ebb _sigtramp + 43
2017-02-13 12:31:01.754 HttpClientTest[3112:47179516] critical: 	3   ???                                 0xffffffff 0x0 + 4294967295
2017-02-13 12:31:01.754 HttpClientTest[3112:47179516] critical: 	4   CFNetwork                           0x02b624c8 _ZN25RequestBodyStreamProvider17_cbBodyReadStreamEP14__CFReadStreammPv + 44
2017-02-13 12:31:01.754 HttpClientTest[3112:47179516] critical: 	5   ???                                 0x11474004 0x0 + 289882116
2017-02-13 12:31:01.755 HttpClientTest[3112:47179516] critical: 	6   ???                                 0x1147424b 0x0 + 289882699
2017-02-13 12:31:01.755 HttpClientTest[3112:47179516] critical: 	7   ???                                 0x11473ede 0x0 + 289881822
2017-02-13 12:31:01.755 HttpClientTest[3112:47179516] critical: 	8   ???                                 0x11473e18 0x0 + 289881624
2017-02-13 12:31:01.755 HttpClientTest[3112:47179516] critical: 	9   ???                                 0x11473d30 0x0 + 289881392
2017-02-13 12:31:01.755 HttpClientTest[3112:47179516] critical: 	10  ???                                 0x1146e9bc 0x0 + 289860028
2017-02-13 12:31:01.756 HttpClientTest[3112:47179516] critical: 	11  ???                                 0x1146ec3a 0x0 + 289860666
2017-02-13 12:31:01.756 HttpClientTest[3112:47179516] critical: 	12  libmonosgen-2.0.dylib               0x034b524d mono_jit_runtime_invoke + 1485
2017-02-13 12:31:01.756 HttpClientTest[3112:47179516] critical: 	13  libmonosgen-2.0.dylib               0x036948bd do_runtime_invoke + 93
2017-02-13 12:31:01.757 HttpClientTest[3112:47179516] critical: 	14  libmonosgen-2.0.dylib               0x03694837 mono_runtime_invoke + 231
2017-02-13 12:31:01.757 HttpClientTest[3112:47179516] critical: 	15  libxamarin-debug.dylib              0x000b2352 xamarin_invoke_trampoline + 6722
2017-02-13 12:31:01.757 HttpClientTest[3112:47179516] critical: 	16  libxamarin-debug.dylib              0x000bb7ec xamarin_arch_trampoline + 156
2017-02-13 12:31:01.757 HttpClientTest[3112:47179516] critical: 	17  libxamarin-debug.dylib              0x000bbe86 xamarin_i386_common_trampoline + 36
2017-02-13 12:31:01.758 HttpClientTest[3112:47179516] critical: 	18  CoreFoundation                      0x0309e603 CFReadStreamScheduleWithRunLoop + 195
2017-02-13 12:31:01.758 HttpClientTest[3112:47179516] critical: 	19  CFNetwork                           0x02bfc320 ___ZNK17CoreSchedulingSet15_scheduleStreamEPvPFvS0_PU28objcproto17OS_dispatch_queue8NSObjectEPFvS0_P11__CFRunLoopPK10__CFStringE_block_invoke + 24
2017-02-13 12:31:01.758 HttpClientTest[3112:47179516] critical: 	20  CFNetwork                           0x029d9e39 _ZNK17CoreSchedulingSet10applyBlockEU13block_pointerFvP11__CFRunLoopPK10__CFStringE + 55
2017-02-13 12:31:01.758 HttpClientTest[3112:47179516] critical: 	21  CFNetwork                           0x02bfc2fe _ZNK17CoreSchedulingSet15_scheduleStreamEPvPFvS0_PU28objcproto17OS_dispatch_queue8NSObjectEPFvS0_P11__CFRunLoopPK10__CFStringE + 112
2017-02-13 12:31:01.758 HttpClientTest[3112:47179516] critical: 	22  CFNetwork                           0x02a2d1c5 _ZNK17CoreSchedulingSet14scheduleStreamEP14__CFReadStream + 51
2017-02-13 12:31:01.759 HttpClientTest[3112:47179516] critical: 	23  CFNetwork                           0x02b6166a _ZN25RequestBodyStreamProvider25scheduleWithSchedulingSetEPK17CoreSchedulingSet + 216
2017-02-13 12:31:01.759 HttpClientTest[3112:47179516] critical: 	24  CFNetwork                           0x02b5d608 ___ZN11HTTP2Stream26scheduleAndOpenWithHandlerEPK17CoreSchedulingSetU13block_pointerFvP15__CFHTTPMessageP15dispatch_data_sPK13CFStreamErrorEU13block_pointerFvhE_block_invoke_2 + 34
2017-02-13 12:31:01.759 HttpClientTest[3112:47179516] critical: 	25  CFNetwork                           0x02af3892 ___ZN15HTTP2Connection13submitRequestENSt3__110shared_ptrI11HTTP2StreamEEU13block_pointerFvvE_block_invoke + 3196
2017-02-13 12:31:01.759 HttpClientTest[3112:47179516] critical: 	26  libdispatch.dylib                   0x0478c6ef _dispatch_client_callout + 14
2017-02-13 12:31:01.759 HttpClientTest[3112:47179516] critical: 	27  libdispatch.dylib                   0x0476ff41 _dispatch_barrier_sync_f_invoke + 112
2017-02-13 12:31:01.760 HttpClientTest[3112:47179516] critical: 	28  libdispatch.dylib                   0x0476fcfa dispatch_barrier_sync_f + 102
2017-02-13 12:31:01.760 HttpClientTest[3112:47179516] critical: 	29  libdispatch.dylib                   0x0476ffa8 dispatch_sync + 41
2017-02-13 12:31:01.760 HttpClientTest[3112:47179516] critical: 	30  CFNetwork                           0x02af2b35 _ZN15HTTP2Connection13submitRequestENSt3__110shared_ptrI11HTTP2StreamEEU13block_pointerFvvE + 409
2017-02-13 12:31:01.760 HttpClientTest[3112:47179516] critical: 	31  CFNetwork                           0x02b5d5c6 ___ZN11HTTP2Stream26scheduleAndOpenWithHandlerEPK17CoreSchedulingSetU13block_pointerFvP15__CFHTTPMessageP15dispatch_data_sPK13CFStreamErrorEU13block_pointerFvhE_block_invoke + 121
2017-02-13 12:31:01.760 HttpClientTest[3112:47179516] critical: 	32  libdispatch.dylib                   0x0478c6ef _dispatch_client_callout + 14
2017-02-13 12:31:01.761 HttpClientTest[3112:47179516] critical: 	33  libdispatch.dylib                   0x0476ff41 _dispatch_barrier_sync_f_invoke + 112
2017-02-13 12:31:01.761 HttpClientTest[3112:47179516] critical: 	34  libdispatch.dylib                   0x0476fcfa dispatch_barrier_sync_f + 102
2017-02-13 12:31:01.761 HttpClientTest[3112:47179516] critical: 	35  libdispatch.dylib                   0x0476ffa8 dispatch_sync + 41
2017-02-13 12:31:01.761 HttpClientTest[3112:47179516] critical: 	36  CFNetwork                           0x02b5d4dc _ZN11HTTP2Stream26scheduleAndOpenWithHandlerEPK17CoreSchedulingSetU13block_pointerFvP15__CFHTTPMessageP15dispatch_data_sPK13CFStreamErrorEU13block_pointerFvhE + 256
2017-02-13 12:31:01.761 HttpClientTest[3112:47179516] critical: 	37  CFNetwork                           0x02b60c29 _ZThn4_N17HTTP2StreamBridge26scheduleAndOpenWithHandlerEPK17CoreSchedulingSetU13block_pointerFvP15__CFHTTPMessageP15dispatch_data_sPK13CFStreamErrorEU13block_pointerFvhE + 27
2017-02-13 12:31:01.762 HttpClientTest[3112:47179516] critical: 	38  CFNetwork                           0x02a16582 _ZN12HTTPProtocol10openStreamEv + 230
2017-02-13 12:31:01.762 HttpClientTest[3112:47179516] critical: 	39  CFNetwork                           0x02a15e5d _ZN12HTTPProtocol26useNetStreamInfoForRequestEP17MetaNetStreamInfoPK18HTTPRequestMessageh + 1725
2017-02-13 12:31:01.762 HttpClientTest[3112:47179516] critical: 	40  CFNetwork                           0x02a4414b _ZThn68_N12HTTPProtocol26useNetStreamInfoForRequestEP17MetaNetStreamInfoPK18HTTPRequestMessageh + 43
2017-02-13 12:31:01.762 HttpClientTest[3112:47179516] critical: 	41  CFNetwork                           0x02b330ef _ZN25HTTP2ConnectionCacheEntry25enqueueRequestForProtocolEP25MetaConnectionCacheClientPK18HTTPRequestMessage21MetaConnectionOptions + 471
2017-02-13 12:31:01.763 HttpClientTest[3112:47179516] critical: 	42  CFNetwork                           0x02b3338f _ZN25HTTP2ConnectionCacheEntry26enqueueAwaitingTubeForTubeEP4Tube + 155
2017-02-13 12:31:01.763 HttpClientTest[3112:47179516] critical: 	43  CFNetwork                           0x02bf92f7 _ZN20HTTP2ConnectionCache10ingestTubeEP4Tubeb + 57
2017-02-13 12:31:01.763 HttpClientTest[3112:47179516] critical: 	44  CFNetwork                           0x029fe8f1 _ZN11TubeManager21_onqueue_newTubeReadyEP4Tube13CFStreamError + 763
2017-02-13 12:31:01.763 HttpClientTest[3112:47179516] critical: 	45  CFNetwork                           0x029fe5ac ___ZN11TubeManager12newTubeReadyEP4Tube13CFStreamError_block_invoke + 74
2017-02-13 12:31:01.763 HttpClientTest[3112:47179516] critical: 	46  libdispatch.dylib                   0x0478c6ef _dispatch_client_callout + 14
2017-02-13 12:31:01.764 HttpClientTest[3112:47179516] critical: 	47  libdispatch.dylib                   0x0476dd79 _dispatch_block_invoke_direct + 347
2017-02-13 12:31:01.764 HttpClientTest[3112:47179516] critical: 	48  libdispatch.dylib                   0x04789e04 ___dispatch_block_create_block_invoke + 20
2017-02-13 12:31:01.764 HttpClientTest[3112:47179516] critical: 	49  CFNetwork                           0x029dbb22 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 24
2017-02-13 12:31:01.764 HttpClientTest[3112:47179516] critical: 	50  CoreFoundation                      0x030120a9 CFArrayApplyFunction + 57
2017-02-13 12:31:01.764 HttpClientTest[3112:47179516] critical: 	51  CFNetwork                           0x029dba1d _ZN19RunloopBlockContext7performEv + 139
2017-02-13 12:31:01.765 HttpClientTest[3112:47179516] critical: 	52  CFNetwork                           0x02a416c8 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
2017-02-13 12:31:01.765 HttpClientTest[3112:47179516] critical: 	53  CFNetwork                           0x029db8b9 _ZN17MultiplexerSource7performEv + 319
2017-02-13 12:31:01.765 HttpClientTest[3112:47179516] critical: 	54  CFNetwork                           0x029db6d8 _ZN17MultiplexerSource8_performEPv + 62
2017-02-13 12:31:01.765 HttpClientTest[3112:47179516] critical: 	55  CoreFoundation                      0x03066edf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
2017-02-13 12:31:01.765 HttpClientTest[3112:47179516] critical: 	56  CoreFoundation                      0x0304afa7 __CFRunLoopDoSources0 + 519
2017-02-13 12:31:01.766 HttpClientTest[3112:47179516] critical: 	57  CoreFoundation                      0x0304a434 __CFRunLoopRun + 1124
2017-02-13 12:31:01.766 HttpClientTest[3112:47179516] critical: 	58  CoreFoundation                      0x03049d5b CFRunLoopRunSpecific + 395
2017-02-13 12:31:01.766 HttpClientTest[3112:47179516] critical: 	59  CoreFoundation                      0x03049bbb CFRunLoopRunInMode + 123
2017-02-13 12:31:01.766 HttpClientTest[3112:47179516] critical: 	60  CFNetwork                           0x029b6c58 +[NSURLConnection(Loader) _resourceLoadLoop:] + 351
2017-02-13 12:31:01.767 HttpClientTest[3112:47179516] critical: 	61  Foundation                          0x001cfbab -[NSThread main] + 68
2017-02-13 12:31:01.767 HttpClientTest[3112:47179516] critical: 	62  Foundation                          0x001cf930 __NSThread__start__ + 1332
2017-02-13 12:31:01.767 HttpClientTest[3112:47179516] critical: 	63  libsystem_pthread.dylib             0x04b0710b _pthread_body + 184
2017-02-13 12:31:01.767 HttpClientTest[3112:47179516] critical: 	64  libsystem_pthread.dylib             0x04b07053 _pthread_body + 0
2017-02-13 12:31:01.767 HttpClientTest[3112:47179516] critical: 	65  libsystem_pthread.dylib             0x04b0690e thread_start + 34
2017-02-13 12:31:01.768 HttpClientTest[3112:47179516] critical: 
=================================================================
Got a SIGSEGV 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 error only occurs in the i386 arch
Comment 3 Manuel de la Peña 2017-02-13 12:47:37 UTC
To provide more information for other team members, the bug is not in the NSUrlSessionhandler perse but in the CFRunLoop and it usage to notify the new content in 386, the following code is where we have the issue:

public override void Schedule (NSRunLoop aRunLoop, string mode)
{
    var cfRunLoop = aRunLoop.GetCFRunLoop ();
    var nsMode = new NSString (mode);

    cfRunLoop.AddSource (source, nsMode);

    if (notifying)
        return;

    notifying = true;
    Notify (CFStreamEventType.HasBytesAvailable);
    notifying = false;

}

If we wrap the code with a 

if (cfRunLoop.ContainsSource (source, nsMode)) {
}

We have a similar crash: 

017-02-13 13:25:56.946 HttpClientTest[36418:47425548] Xamarin.iOS: Established connection with the IDE (fd: 6)
2017-02-13 13:25:56.946 HttpClientTest[36418:47425540] Xamarin.iOS: Debugger loaded with custom transport (fd: 4)
2017-02-13 13:25:56.947 HttpClientTest[36418:47425548] Xamarin.iOS: Processing: 'start profiler: no'
2017-02-13 13:25:56.948 HttpClientTest[36418:47425540] Xamarin.iOS: Profiler not loaded (disabled)
2017-02-13 13:25:56.986 HttpClientTest[36418:47425540] Xamarin.iOS: Added dllmap for objc_msgSend
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/18FC371E-BCE2-46B1-970A-1327A95DA96D/HttpClientTest.app/Xamarin.iOS.dll
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/18FC371E-BCE2-46B1-970A-1327A95DA96D/HttpClientTest.app/System.dll
Thread started:  #2
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/18FC371E-BCE2-46B1-970A-1327A95DA96D/HttpClientTest.app/HttpClientTest.exe
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/18FC371E-BCE2-46B1-970A-1327A95DA96D/HttpClientTest.app/System.Net.Http.dll
Loaded assembly: /Users/mandel/Library/Developer/CoreSimulator/Devices/32DE56F1-F7F1-4032-A3B0-EF8DAA62AFE5/data/Containers/Bundle/Application/18FC371E-BCE2-46B1-970A-1327A95DA96D/HttpClientTest.app/System.Core.dll
Resolved pending breakpoint at 'ViewController.cs:23,1' to void HttpClientTest.ViewController.<ViewDidLoad>c__async0.MoveNext () [0x00063].
Thread started:  #4
Thread started:  #5
Thread started:  #6
2017-02-13 13:26:02.072 HttpClientTest[36418:47425876] Scheduling!!
2017-02-13 13:26:02.073 HttpClientTest[36418:47425876] Testing if the source was indeed added kCFRunLoopDefaultMode
2017-02-13 13:26:02.076 HttpClientTest[36418:47425876] critical: Stacktrace:

2017-02-13 13:26:02.076 HttpClientTest[36418:47425876] critical:   at <unknown> <0xffffffff>
2017-02-13 13:26:02.076 HttpClientTest[36418:47425876] critical:   at (wrapper managed-to-native) object.wrapper_native_0x2b4c49c (intptr,CoreFoundation.CFStreamEventType,intptr) <0x00012>
2017-02-13 13:26:02.077 HttpClientTest[36418:47425876] critical:   at (wrapper delegate-invoke) <Module>.invoke_void_intptr_CFStreamEventType_intptr (intptr,CoreFoundation.CFStreamEventType,intptr) [0x00061] in <fce54f24b1e3468fb3b4130c39c10556>:0
2017-02-13 13:26:02.077 HttpClientTest[36418:47425876] critical:   at CoreFoundation.CFStreamClientContext.CFReadStreamRef_InvokeCallback (intptr,intptr,CoreFoundation.CFStreamEventType,intptr) [0x00000] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/CoreFoundation/CFStream.cs:138
2017-02-13 13:26:02.077 HttpClientTest[36418:47425876] critical:   at CoreFoundation.CFStreamClientContext.Invoke (intptr,intptr,CoreFoundation.CFStreamEventType) [0x00011] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/CoreFoundation/CFStream.cs:106
2017-02-13 13:26:02.077 HttpClientTest[36418:47425876] critical:   at Foundation.NSInputStream.Notify (CoreFoundation.CFStreamEventType) [0x00010] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/Foundation/NSInputStream.cs:116
2017-02-13 13:26:02.077 HttpClientTest[36418:47425876] critical:   at System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Read (intptr,System.nuint) [0x00073] in /Users/mandel/Xamarin/maccore-master/xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:595
2017-02-13 13:26:02.078 HttpClientTest[36418:47425876] critical:   at (wrapper runtime-invoke) <Module>.runtime_invoke_nint__this___intptr_nuint (object,intptr,intptr,intptr) [0x0006d] in <b7330e23c01a46a691983ae38849b8bd>:0
2017-02-13 13:26:02.078 HttpClientTest[36418:47425876] critical: 
Native stacktrace:

2017-02-13 13:26:02.085 HttpClientTest[36418:47425876] critical: 	0   libmonosgen-2.0.dylib               0x0355654d mono_handle_native_sigsegv + 317
2017-02-13 13:26:02.085 HttpClientTest[36418:47425876] critical: 	1   libmonosgen-2.0.dylib               0x0349b803 mono_sigsegv_signal_handler + 323
2017-02-13 13:26:02.085 HttpClientTest[36418:47425876] critical: 	2   libsystem_platform.dylib            0x04ae5ebb _sigtramp + 43
2017-02-13 13:26:02.085 HttpClientTest[36418:47425876] critical: 	3   ???                                 0xffffffff 0x0 + 4294967295
2017-02-13 13:26:02.085 HttpClientTest[36418:47425876] critical: 	4   ???                                 0x1144dabc 0x0 + 289725116
2017-02-13 13:26:02.085 HttpClientTest[36418:47425876] critical: 	5   ???                                 0x1144dd03 0x0 + 289725699
2017-02-13 13:26:02.086 HttpClientTest[36418:47425876] critical: 	6   ???                                 0x1144d996 0x0 + 289724822
2017-02-13 13:26:02.086 HttpClientTest[36418:47425876] critical: 	7   ???                                 0x1144d8d0 0x0 + 289724624
2017-02-13 13:26:02.086 HttpClientTest[36418:47425876] critical: 	8   ???                                 0x1144d7e8 0x0 + 289724392
2017-02-13 13:26:02.086 HttpClientTest[36418:47425876] critical: 	9   ???                                 0x1144e2d0 0x0 + 289727184
2017-02-13 13:26:02.086 HttpClientTest[36418:47425876] critical: 	10  ???                                 0x1144e5ae 0x0 + 289727918
2017-02-13 13:26:02.086 HttpClientTest[36418:47425876] critical: 	11  libmonosgen-2.0.dylib               0x0349f24d mono_jit_runtime_invoke + 1485
2017-02-13 13:26:02.087 HttpClientTest[36418:47425876] critical: 	12  libmonosgen-2.0.dylib               0x0367e8bd do_runtime_invoke + 93
2017-02-13 13:26:02.087 HttpClientTest[36418:47425876] critical: 	13  libmonosgen-2.0.dylib               0x0367e837 mono_runtime_invoke + 231
2017-02-13 13:26:02.087 HttpClientTest[36418:47425876] critical: 	14  libxamarin-debug.dylib              0x000a5352 xamarin_invoke_trampoline + 6722
2017-02-13 13:26:02.087 HttpClientTest[36418:47425876] critical: 	15  libxamarin-debug.dylib              0x000ae7ec xamarin_arch_trampoline + 156
2017-02-13 13:26:02.087 HttpClientTest[36418:47425876] critical: 	16  libxamarin-debug.dylib              0x000aee86 xamarin_i386_common_trampoline + 36
2017-02-13 13:26:02.088 HttpClientTest[36418:47425876] critical: 	17  CoreFoundation                      0x0302c0db CFReadStreamRead + 619
2017-02-13 13:26:02.088 HttpClientTest[36418:47425876] critical: 	18  CFNetwork                           0x02b4c2eb _ZN25RequestBodyStreamProvider14readBodyStreamEb + 283
2017-02-13 13:26:02.088 HttpClientTest[36418:47425876] critical: 	19  CFNetwork                           0x02b4c1cb ___ZN25RequestBodyStreamProvider22scheduleReadBodyStreamEb_block_invoke + 25
2017-02-13 13:26:02.088 HttpClientTest[36418:47425876] critical: 	20  libdispatch.dylib                   0x047806ef _dispatch_client_callout + 14
2017-02-13 13:26:02.088 HttpClientTest[36418:47425876] critical: 	21  libdispatch.dylib                   0x04761d79 _dispatch_block_invoke_direct + 347
2017-02-13 13:26:02.088 HttpClientTest[36418:47425876] critical: 	22  libdispatch.dylib                   0x0477de04 ___dispatch_block_create_block_invoke + 20
2017-02-13 13:26:02.089 HttpClientTest[36418:47425876] critical: 	23  CFNetwork                           0x029c5b22 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 24
2017-02-13 13:26:02.089 HttpClientTest[36418:47425876] critical: 	24  CoreFoundation                      0x02ffc0a9 CFArrayApplyFunction + 57
2017-02-13 13:26:02.090 HttpClientTest[36418:47425876] critical: 	25  CFNetwork                           0x029c5a1d _ZN19RunloopBlockContext7performEv + 139
2017-02-13 13:26:02.090 HttpClientTest[36418:47425876] critical: 	26  CFNetwork                           0x02a2b6c8 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
2017-02-13 13:26:02.090 HttpClientTest[36418:47425876] critical: 	27  CFNetwork                           0x029c58b9 _ZN17MultiplexerSource7performEv + 319
2017-02-13 13:26:02.091 HttpClientTest[36418:47425876] critical: 	28  CFNetwork                           0x029c56d8 _ZN17MultiplexerSource8_performEPv + 62
2017-02-13 13:26:02.091 HttpClientTest[36418:47425876] critical: 	29  CoreFoundation                      0x03050edf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
2017-02-13 13:26:02.091 HttpClientTest[36418:47425876] critical: 	30  CoreFoundation                      0x03034fa7 __CFRunLoopDoSources0 + 519
2017-02-13 13:26:02.091 HttpClientTest[36418:47425876] critical: 	31  CoreFoundation                      0x03034434 __CFRunLoopRun + 1124
2017-02-13 13:26:02.091 HttpClientTest[36418:47425876] critical: 	32  CoreFoundation                      0x03033d5b CFRunLoopRunSpecific + 395
2017-02-13 13:26:02.092 HttpClientTest[36418:47425876] critical: 	33  CoreFoundation                      0x03033bbb CFRunLoopRunInMode + 123
2017-02-13 13:26:02.092 HttpClientTest[36418:47425876] critical: 	34  CFNetwork                           0x029a0c58 +[NSURLConnection(Loader) _resourceLoadLoop:] + 351
2017-02-13 13:26:02.092 HttpClientTest[36418:47425876] critical: 	35  Foundation                          0x001b9bab -[NSThread main] + 68
2017-02-13 13:26:02.092 HttpClientTest[36418:47425876] critical: 	36  Foundation                          0x001b9930 __NSThread__start__ + 1332
2017-02-13 13:26:02.092 HttpClientTest[36418:47425876] critical: 	37  libsystem_pthread.dylib             0x04af610b _pthread_body + 184
2017-02-13 13:26:02.093 HttpClientTest[36418:47425876] critical: 	38  libsystem_pthread.dylib             0x04af6053 _pthread_body + 0
2017-02-13 13:26:02.093 HttpClientTest[36418:47425876] critical: 	39  libsystem_pthread.dylib             0x04af590e thread_start + 34
2017-02-13 13:26:02.093 HttpClientTest[36418:47425876] critical: 
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Comment 4 Manuel de la Peña 2017-02-15 17:37:02 UTC
Attaching a project with a similar implementation of the NSInputStream used in the handler, interestingly the source is added AND the notify does not crash. I have a feeling that is due to the fact that we are not calling the NSInputStream.SetCFClientFlags, I'm looking into doing that to see if the crash can be reproduced.

Nevertheless we do have an issue in the NSStream bindings, as per documentation:


delegate:

By default, a stream is its own delegate, and subclasses of NSInputStream and NSOutputStream must maintain this contract. If you override this method in a subclass, passing nil must restore the receiver as its own delegate. Delegates are not retained.
To learn about delegates and delegation, read "Delegation" in Cocoa Fundamentals Guide.


Yet, we have defined the NSStream class as:


[BaseType (typeof (NSObject), Delegates=new string [] { "WeakDelegate" }, Events=new Type [] { typeof (NSStreamDelegate)} )]
interface NSStream {
    [Export ("open")]
    void Open ();

    [Export ("close")]
    void Close ();
	
    [Export ("delegate", ArgumentSemantic.Assign), NullAllowed]
    NSObject WeakDelegate { get; set; }
..
}

This means that we cannot override the Delegate and that the NSInputStream and NSOuputStream cannot set the delegate to self (this in c#) because we will have the following objc exception:

Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: *** -setDelegate: only defined for abstract class.  Define -[CFRuntimeTest_NSInputStreamTest setDelegate:]!
Comment 5 Manuel de la Peña 2017-02-15 17:38:32 UTC
Created attachment 19826 [details]
NSInputStream example app.
Comment 6 Sebastien Pouliot 2017-02-15 20:07:42 UTC
@Manuel found some interesting hints on what could be causing the issue and I'll be looking at them shortly.

I'm lowering the bug priority and moving it out of C9 scope since the issue only exists on the 32bits simulator (i386) when linking is enabled (not the default for simulator builds). Both conditions can be worked around and won't affect shipping code.
Comment 7 Manuel de la Peña 2017-02-17 15:57:40 UTC
Created attachment 19866 [details]
Error test app

Simple test app that shows the issue.
Comment 8 Sebastien Pouliot 2017-02-17 21:13:45 UTC
The linker part turned out to be a red herring. It's likely that the code worked did not crash in some execution (low % since I could not reproduce it).

The issue was a 32/64 bits error wrt to the usage of the `CFStreamEventType` enum (which is based on `NSUInteger`, same size as the arch). We had a native delegate using it and that made it incorrect on 32bits platforms.

We already have tests for this (at least p/invoke) but it seems they don't cover native delegates :( We'll be expanding them to cover this less usual case.

PR master https://github.com/xamarin/xamarin-macios/pull/1714
Comment 10 Mohak Barokar 2017-03-22 11:59:55 UTC
Created attachment 20656 [details]
Bug_52279 Ide Logs and Build output Stacktrace

Verified this bug on following configuration :

=== Xamarin Studio Enterprise ===

Version 6.3 (build 853)
Installation UUID: 2adb7e6f-cff5-443b-a1c2-9cd618f4c8e6
Runtime:
 Mono 4.8.0 (mono-4.8.0-branch/9d74414) (64-bit)
 GTK+ 2.24.23 (Raleigh theme)

 Package version: 408000524

=== NuGet ===

Version: 3.5.0.0

=== Xamarin.Profiler ===

'/Applications/Xamarin Profiler.app' not found

=== Apple Developer Tools ===

Xcode 8.2.1 (11766.1)
Build 8C1002

=== Xamarin.iOS ===

Version: 10.8.0.27 (Visual Studio Enterprise Trial)
Hash: 9c31d85
Branch: d15-1
Build date: 2017-03-21 09:34:27-0400

=== Xamarin Inspector ===

Version: 1.2.0-rc+build.12
Hash: 46fd2cd
Branch: d15-1
Build date: Wed, 01 Mar 2017 21:53:36 GMT

=== Xamarin.Mac ===

Version: 3.2.0.27 (Visual Studio Enterprise Trial)

=== Xamarin.Android ===

Version: 7.2.0.6 (Visual Studio Enterprise Trial)
Android SDK: /Users/globallogic/Library/Developer/Xamarin/android-sdk-macosx
 Supported Android versions:
  2.3 (API level 10)
  4.4 (API level 19)
  6.0 (API level 23)
  7.0 (API level 24)
  7.1 (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.3
SDK Build Tools Version: 25.0.1

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

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

=== Build Information ===

Release ID: 603000853
Git revision: e2019d10e6726829235930d61891599a299355ec
Build date: 2017-03-20 16:03:27-04
Xamarin addins: e99b90462c4f9ec52e982ae747f1213fdaafacfc
Build lane: monodevelop-lion-d15-1

=== Operating System ===

Mac OS X 10.12.3
Darwin NAG1-DMAC-26499 16.4.0 Darwin Kernel Version 16.4.0
    Thu Dec 22 22:53:21 PST 2016
    root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

The attached example app was deployed on Simulators iphone 7 iOS 10.2, iPhone 6s iOS 10.2 and iPhone 6s iOS 9.3 and the App was not crashed. Hence marking this bug as Verified.

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