Bug 59793 - NSURLSessionConfiguration Discretionary property breaks redirects.
Summary: NSURLSessionConfiguration Discretionary property breaks redirects.
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 11.0 (xcode9)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.6
Assignee: Manuel de la Peña
Depends on:
Reported: 2017-09-27 15:39 UTC by Chris Mays
Modified: 2017-12-11 15:45 UTC (History)
4 users (show)

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


Description Chris Mays 2017-09-27 15:39:15 UTC
I am running into a potential Xamarin bug involving background NSURLSessionConfiguration. Apple recommends that you set the Discretionary property to true so that the system can control when transfers occur. Whenever I turn this on in a Xamarin project and the session encounters a redirect I get this error `The operation couldn't be completed. Invalid argument`. After a lot of debugging I created an exact replica native project to see if I encountered the same error. The native project successfully follows the redirect and performs the download. The really unsettling thing about this is when I attach to the Xamarin project through lldb it successfully follows the redirect and the download succeeds (maybe race condition?). I have two example projects available if anyone wants to try this out:
Comment 1 Chris Mays 2017-09-27 15:53:35 UTC
=== Visual Studio Community 2017 for Mac ===

Version 7.1.5 (build 2)
Installation UUID: d20c7b96-88fc-40f7-9bc7-7346b6036c58
	Mono (d15-3/14f2c81) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 502000224

=== NuGet ===


=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
SDK: /usr/local/share/dotnet/sdk/1.0.3/Sdks
SDK Version: 1.0.3
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.2.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.5.5
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: (Visual Studio Community)
Android SDK: /Users/chrismays/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		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.5
SDK Build Tools Version: 25.0.3

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

Android Designer EPL code available here:

=== Apple Developer Tools ===

Xcode 9.0 (13247)
Build 9A235

=== Xamarin.iOS ===

Version: (Visual Studio Community)
Hash: 152b654a
Branch: xcode9
Build date: 2017-09-15 02:25:56-0400

=== Xamarin.Mac ===

Version: (Visual Studio Community)

=== Xamarin Inspector ===

Version: 1.3.0
Hash: 8c298a5
Branch: 1.3-release
Build date: Thu, 14 Sep 2017 21:21:26 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 701050002
Git revision: 7afedcaef8e7542e70e3cf8f9bdb26938b8c0876
Build date: 2017-09-15 08:39:58-04
Xamarin addins: 3262aadf811a18c12eac6742532d052b0139a808
Build lane: monodevelop-lion-d15-3-xcode9

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
    Thu Jun 15 17:36:27 PDT 2017
    root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Comment 2 John Miller [MSFT] 2017-09-27 16:07:36 UTC
I am able to reproduce using the projects provided. 

The Xamarin.iOS project output:

> 2017-09-27 11:52:00.179 Discrectionary[1714:313567] Error Downloading: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument" UserInfo={_kCFStreamErrorCodeKey=22, _kCFStreamErrorDomainKey=1}

The Xcode obj-c project output:

> 2017-09-27 11:59:29.425863-0400 Discretionary-Native[1860:320227] Downloaded to location file:///Users/johnmiller/Library/Developer/CoreSimulator/Devices/E665DD79-E8A0-49C9-A3ED-76BA92EA140A/data/Containers/Data/Application/49173AA0-2993-4DA0-95A3-32E92EDF8122/Library/Caches/com.apple.nsurlsessiond/Downloads/com.NSChris.Discretionary-Native/CFNetworkDownload_I9jDYW.tmp

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