Bug 59793 - NSURLSessionConfiguration Discretionary property breaks redirects.
Summary: NSURLSessionConfiguration Discretionary property breaks redirects.
Status: CONFIRMED
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: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-27 15:39 UTC by Chris Mays
Modified: 2017-09-28 03:45 UTC (History)
3 users (show)

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


Attachments

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:
https://github.com/chrsmys/NSURLSession-Discretionary-Xamarin
https://github.com/chrsmys/NSURLSession-Discretionary-Native
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
Runtime:
	Mono 5.2.0.224 (d15-3/14f2c81) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 502000224

=== NuGet ===

Version: 4.3.0.2418

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	1.1.1
	1.0.4
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: 7.4.5.1 (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:
https://github.com/xamarin/AndroidDesigner.EPL

=== Apple Developer Tools ===

Xcode 9.0 (13247)
Build 9A235

=== Xamarin.iOS ===

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

=== Xamarin.Mac ===

Version: 3.6.3.3 (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.