Bug 41628 - CFNetwork and NSUrlSession handlers can't be reused
Summary: CFNetwork and NSUrlSession handlers can't be reused
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.8 (tvOS / C7)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Sebastien Pouliot
Depends on:
Reported: 2016-06-09 01:30 UTC by Sebastien Pouliot
Modified: 2016-08-22 18:41 UTC (History)
3 users (show)

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

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 Sebastien Pouliot 2016-06-09 01:30:48 UTC
from #41514

> Also when using NSUrlSession or CFNetwork in xamarin studio options, HttpClient can
> not be used as a singleton anymore to make multiple simultaneous calls. It seems
> HttpClient is now stateful instead of stateless.
Comment 1 Sebastien Pouliot 2016-06-09 17:15:08 UTC
My earlier test was incorrect as it changed an handler property before re-using it (the exception was normal as this was not thread safe to do so).

Once I removed that I could issue more than one request using HttpClient for both the managed HttpClientHandler and the NSUrlSessionHandler (see code below).

It's possible you're hitting a different code path that cause the issue. We'll need a self-contained test case that shows the issue to see what's going on.

		Task<string> Get (HttpClient client)
			return Task.Run (async () => await client.GetStringAsync ("http://xamarin.com"));

		// same HttpClient and handler doing two simultaneous calls
		void DualGet (HttpMessageHandler handler)
			using (var client = new HttpClient (handler)) {
				var get1 = Get (client);
				var get2 = Get (client);
				get1.Wait ();
				get2.Wait ();

		public void ManagedDual ()
			DualGet (new HttpClientHandler ());

		public void NSDual ()
			DualGet (new NSUrlSessionHandler ());
Comment 2 Sebastien Pouliot 2016-07-06 19:28:13 UTC
Moving off the SR1 milestone as our own tests do not reach the original situation that was described.
Comment 3 Alex Soto [MSFT] 2016-08-22 18:31:07 UTC
Hello Benjamin!

We have not received the requested information. If you are still 
experiencing this issue please provide all the requested information 
and re-open the bug report. Thanks!
Comment 4 softlion 2016-08-22 18:41:48 UTC
Where is my bug 41514 ?