Skip to content

App crash due to NullReferenceException in NSUrlSessionHandlerDelegate.DidCompleteWithError #11799

Closed

Description

@adams-family

IMPORTANT:

I think this problem will be somewhat related to: #9132

Steps to Reproduce

I happens on iOS, latest versions (latest iOS, latest Xamarin) very often in production (tens of crashes per day on a 2k user basis), randomly. It's hard to reproduce it in the debugger.

protected HttpClient client = new HttpClient();

void Test()
{
  try
  {
     var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
     stringContent.Headers.Add("sample", "value");
     var response = await client.PostAsync("https://....", stringContent);
  }
  catch (Exception e)
  {
     // it never hits this exception handler
  }
}

Expected Behavior

Thanks to the try/catch block this code should never cause an app crash.

Actual Behavior

The app crashes. Here is an AppCenter stacktrace:

NSUrlSessionHandler+NSUrlSessionHandlerDelegate.DidCompleteWithError (Foundation.NSUrlSession session, Foundation.NSUrlSessionTask task, Foundation.NSError error)

Environment

Microsoft Visual Studio Community 2019
Version 16.8.4
VisualStudio.16.Release/16.8.4+30907.101
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2019   00435-60000-00000-AA591
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.8.557.25636
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0   16.8.557.25636
Azure App Service Tools v3.0.0

C# Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IncrediBuild Build Acceleration   1.5.0.13
IncrediBuild effectively reduces compilation and development times by up to 90%.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.8.43 (00471f8)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.8.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Qt Visual Studio Tools   2.7.1.18
The Qt Visual Studio Tools allow developers to use the standard development environment without having to worry about any Qt-related build steps or tools.

Syncfusion ASP.NET Core Project Templates   18.1.0.42
Provides project templates for creating an ASP.NET Core Web Application using Syncfusion ASP.NET Core components.

Syncfusion ASP.NET Core Project Templates   16.1.0.32
Provides project templates for creating an ASP.NET Core Web Application using Syncfusion ASP.NET Core components.

Syncfusion ASP.NET MVC Project Templates   17.1.0.32
Provides project templates for creating ASP.NET MVC Web Applications using Syncfusion components.

Syncfusion Xamarin Project Templates   13.4.0.53
A multi-project template for building iOS, Android, and Windows apps using Syncfusion Xamarin components.

Syncfusion Xamarin Toolbox   16.2.0.19
Syncfusion Essential Studio for Xamarin Toolbox Visual Studio extension.

SyncfusionMenu Extension   1.0
SyncfusionMenu Visual Studio Extension Detailed Info

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

Visual Basic Tools   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.8.000.261 (d16-8@bb99248)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.8.0.507 (remotes/origin/d16-8@e87b24884)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.8.112 (86385a3)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.1.0.26 (d16-8/a36ce73)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 5e9cb6d
    Java.Interop: xamarin/java.interop/d16-8@79d9533
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc


Xamarin.iOS and Xamarin.Mac SDK   14.8.0.3 (c51fabee8)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Example Project (If Possible)

I don't think it's possible to create one because I'd need to roll it out to at least a thousand users.

Activity

  1. added
    iOS
    need-info
    on Jun 3, 2021
  2. added this to the Future milestone on Jun 3, 2021
  3. added
    bug
    on Jun 3, 2021
  4. spouliot commented on Jun 3, 2021

    @spouliot
    Contributor

    I think this problem will be somewhat related to: #9132

    c.c. @mandel-macaque

    I don't think it's possible to create one because I'd need to roll it out to at least a thousand users.

    Can you provide us with a complete, symbolicated crash report ?

    Sadly the stack trace above is not telling us much about what's happening.

    Thanks!

  5. mandel-macaque commented on Jun 3, 2021

    @mandel-macaque
    Contributor

    @spouliot @adams-family looking at the Xamarin.iOS version:

    Xamarin.iOS and Xamarin.Mac SDK 14.8.0.3 (c51fabe)

    That points to commit: c51fabee8 that commits is earlier than the fix provided in #10230

    If you look at the source code of the commit of the version you are using https://github.com/xamarin/xamarin-macios/blob/c51fabee8aa096e83f7a781aecba68113613b71d/src/Foundation/NSUrlSessionHandler.cs#L543 you can see that the fix I provided is not there. It is the same bug, but you are in a much older version which means that you do not have the fix.

    The current stable release is https://download.visualstudio.microsoft.com/download/pr/414d1675-ca0b-4b5b-8a4e-26b693883581/5e50228d1498caf85151b6d6cfec6fd9/xamarin.ios-14.20.0.1.pkg

    Please, make sure that you are running the latests stable and then we can re-visit the issue.

    (Edit: updated pkg to d16-10 which also has the fix)

  6. added
    support
    and removed
    need-info
    on Jun 3, 2021
  7. adams-family commented on Jun 4, 2021

    @adams-family
    Author

    Hi @mandel-macaque

    I double-checked and the machine used to build the iOS version before releasing to the AppStore was this one: Xamarin.iOS 14.14.2.5.

    === Visual Studio Community 2019 for Mac ===
    
    Version 8.9.1 (build 34)
    Installation UUID: 7d21187b-92bc-43a9-ab04-339062ddf7e1
    	GTK+ 2.24.23 (Raleigh theme)
    	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)
    
    	Package version: 612000122
    
    === Mono Framework MDK ===
    
    Runtime:
    	Mono 6.12.0.122 (2020-02/c621c35ffa0) (64-bit)
    	Package version: 612000122
    
    === Roslyn (Language Service) ===
    
    3.9.0-6.21152.10+c10f884b30737542ddd84ca889a4aad9281ce210
    
    === NuGet ===
    
    Version: 5.8.0.6860
    
    === .NET Core SDK ===
    
    SDK: /usr/local/share/dotnet/sdk/5.0.201/Sdks
    SDK Versions:
    	5.0.201
    	3.1.407
    MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks
    
    === .NET Core Runtime ===
    
    Runtime: /usr/local/share/dotnet/dotnet
    Runtime Versions:
    	5.0.4
    	3.1.13
    
    === .NET Core 3.1 SDK ===
    
    SDK: 3.1.407
    
    === Xamarin.Profiler ===
    
    Version: 1.6.15.68
    Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
    
    === Updater ===
    
    Version: 11
    
    === Apple Developer Tools ===
    
    Xcode 12.5 (18205)
    Build 12E262
    
    === Xamarin.Mac ===
    
    Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.
    
    === Xamarin.iOS ===
    
    Version: 14.14.2.5 (Visual Studio Community)
    Hash: 3836759d4
    Branch: d16-9
    Build date: 2021-02-10 17:56:44-0500
    
    === Xamarin Designer ===
    
    Version: 16.9.0.316
    Hash: bd2705417
    Branch: remotes/origin/d16-9
    Build date: 2021-02-24 00:16:08 UTC
    
    === Xamarin.Android ===
    
    Version: 11.2.0.21 (Visual Studio Community)
    Commit: xamarin-android/d16-9/93eab59
    Android SDK: /Users/adam/Library/Developer/Xamarin/android-sdk-macosx
    	Supported Android versions:
    		None installed
    
    SDK Tools Version: 26.1.1
    SDK Platform Tools Version: 30.0.4
    SDK Build Tools Version: 30.0.2
    
    Build Information: 
    Mono: 5e9cb6d
    Java.Interop: xamarin/java.interop/d16-9@d6d86b2
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.34.1@daff8f4
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@9d8924d
    
    === Microsoft OpenJDK for Mobile ===
    
    Java SDK: /Users/adam/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
    1.8.0-25
    Android Designer EPL code available here:
    https://github.com/xamarin/AndroidDesigner.EPL
    
    === Android SDK Manager ===
    
    Version: 16.9.0.22
    Hash: a391de2
    Branch: remotes/origin/d16-9
    Build date: 2021-02-18 03:14:56 UTC
    
    === Android Device Manager ===
    
    Version: 16.9.0.17
    Hash: fc2b3db
    Branch: remotes/origin/d16-9
    Build date: 2021-02-18 03:15:18 UTC
    
    === Build Information ===
    
    Release ID: 809010034
    Git revision: 33bce2b7f3d45d05865cd3282f1c2cdc3a112aa0
    Build date: 2021-03-04 11:21:38-05
    Build branch: release-8.9
    Xamarin extensions: 33bce2b7f3d45d05865cd3282f1c2cdc3a112aa0
    
    === Operating System ===
    
    Mac OS X 10.16.0
    Darwin 20.3.0 Darwin Kernel Version 20.3.0
        Thu Jan 21 00:07:06 PST 2021
        root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
    
  8. adams-family commented on Jun 4, 2021

    @adams-family
    Author

    @spouliot - I have exported a crashreport from MS AppCenter, symbols were uploaded earlier therefore I hope it's useful to you:

    Incident Identifier: d4c93912-92f7-4860-8988-***********
    CrashReporter Key:   AB6B1072-8B29-4B32-8D24-***********
    Hardware Model:      iPhone12,1
    Process:         application.iOS [743]
    Path:            /private/var/containers/Bundle/Application/B99CA9E0-70E0-4203-9EA3-7EB8B6B892B1/application/application.iOS
    Identifier:      *****
    Version:         1.1.6 (184)
    Code Type:       arm64
    Parent Process:   [1]
    
    Date/Time:       2021-06-03T10:08:06.999Z
    Launch Time:     2021-06-01T03:28:08Z
    OS Version:      iPhone OS 14.4.2 (18D70)
    Report Version:  104
    
    Exception Type:  SIGABRT
    Exception Codes: #0 at 0x1b4f51414
    Crashed Thread:  20
    
    Application Specific Information:
    *** Terminating app due to uncaught exception 'SIGABRT', reason: 'Object reference not set to an instance of an object'
    
    Xamarin Exception Stack:
    System.NullReferenceException: Object reference not set to an instance of an object
      at System.Net.Http.NSUrlSessionHandler+NSUrlSessionHandlerDelegate.DidCompleteWithError (Foundation.NSUrlSession session, Foundation.NSUrlSessionTask task, Foundation.NSError error) <0x105cc29f0 + 0x00074> in <ad1be307855442e4b2cb88e33f94f908#8bd8601acf85cfa73490ae975776a7b0>:0
    
    Thread 20 Crashed:
    0   libsystem_kernel.dylib               0x00000001b4f51414 __pthread_kill + 8
    1   libsystem_c.dylib                    0x000000019042fb74 abort + 100
    2   application.iOS                      0x000000010671f9f8 0x104d98000 + 26769912
    3   application.iOS                      0x00000001065e494c 0x104d98000 + 25479500
    4   application.iOS                      0x0000000106579718 0x104d98000 + 25040664
    5   application.iOS                      0x0000000106578100 0x104d98000 + 25035008
    6   application.iOS                      0x000000010656e404 0x104d98000 + 24994820
    
    Thread 0:
    0   application.iOS                      0x00000001051b7fe0 0x104d98000 + 4325344
    1   application.iOS                      0x00000001050353d4 0x104d98000 + 2741204
    2   application.iOS                      0x0000000104edd180 0x104d98000 + 1331584
    3   application.iOS                      0x0000000104edaa74 0x104d98000 + 1321588
    4   application.iOS                      0x0000000104f8fd24 0x104d98000 + 2063652
    5   application.iOS                      0x0000000104eb1fd0 0x104d98000 + 1155024
    6   application.iOS                      0x0000000104eb1e70 0x104d98000 + 1154672
    7   application.iOS                      0x0000000104f85b5c 0x104d98000 + 2022236
    8   application.iOS                      0x0000000104f85be4 0x104d98000 + 2022372
    9   application.iOS                      0x000000010501388c 0x104d98000 + 2603148
    10  application.iOS                      0x0000000105013454 0x104d98000 + 2602068
    11  application.iOS                      0x0000000105012f8c 0x104d98000 + 2600844
    12  application.iOS                      0x0000000105013afc 0x104d98000 + 2603772
    13  application.iOS                      0x0000000105013bd4 0x104d98000 + 2603988
    14  application.iOS                      0x0000000104ed65b4 0x104d98000 + 1303988
    15  application.iOS                      0x0000000104ebdfb4 0x104d98000 + 1204148
    16  application.iOS                      0x0000000104ebe34c 0x104d98000 + 1205068
    17  application.iOS                      0x0000000104ebe16c 0x104d98000 + 1204588
    18  application.iOS                      0x00000001060a3b98 0x104d98000 + 19970968
    19  application.iOS                      0x0000000104f6e7fc 0x104d98000 + 1927164
    20  application.iOS                      0x0000000104ef670c 0x104d98000 + 1435404
    21  application.iOS                      0x0000000104ef650c 0x104d98000 + 1434892
    22  application.iOS                      0x0000000104f6e6b8 0x104d98000 + 1926840
    23  application.iOS                      0x0000000104f12e98 0x104d98000 + 1552024
    24  application.iOS                      0x0000000105d3d78c 0x104d98000 + 16406412
    25  application.iOS                      0x0000000105178a00 0x104d98000 + 4065792
    26  application.iOS                      0x000000010658b33c 0x104d98000 + 25113404
    27  application.iOS                      0x0000000106646a60 0x104d98000 + 25881184
    28  application.iOS                      0x000000010664a2c4 0x104d98000 + 25895620
    29  application.iOS                      0x0000000104dd6020 0x104d98000 + 253984
    30  application.iOS                      0x0000000104dd8040 0x104d98000 + 262208
    31  Foundation                           0x0000000188397b90 __NSThreadPerformPerform + 184
    32  CoreFoundation                       0x0000000186f7d76c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    33  CoreFoundation                       0x0000000186f7d668 __CFRunLoopDoSource0 + 204
    34  CoreFoundation                       0x0000000186f7c960 __CFRunLoopDoSources0 + 264
    35  CoreFoundation                       0x0000000186f76a8c __CFRunLoopRun + 820
    36  CoreFoundation                       0x0000000186f7621c CFRunLoopRunSpecific + 596
    37  GraphicsServices                     0x000000019eb40784 GSEventRunModal + 160
    38  UIKitCore                            0x00000001899b6ee8 -[UIApplication _run] + 1068
    39  UIKitCore                            0x00000001899bc75c UIApplicationMain + 164
    40  application.iOS                      0x0000000105d950d8 0x104d98000 + 16765144
    41  application.iOS                      0x0000000105cf1ee0 0x104d98000 + 16096992
    42  application.iOS                      0x0000000105cf1e64 0x104d98000 + 16096868
    43  application.iOS                      0x0000000104dff744 0x104d98000 + 423748
    44  application.iOS                      0x0000000105178a00 0x104d98000 + 4065792
    45  application.iOS                      0x000000010658b33c 0x104d98000 + 25113404
    46  application.iOS                      0x0000000106646a60 0x104d98000 + 25881184
    47  application.iOS                      0x000000010664ccb8 0x104d98000 + 25906360
    48  application.iOS                      0x00000001065698d0 0x104d98000 + 24975568
    49  application.iOS                      0x0000000106727488 0x104d98000 + 26801288
    50  application.iOS                      0x0000000104dff650 0x104d98000 + 423504
    51  libdyld.dylib                        0x0000000186c366b0 start + 0
    
    Thread 1:
    0   libsystem_kernel.dylib               0x00000001b4f511ac __psynch_cvwait + 8
    1   application.iOS                      0x00000001066ea3d0 0x104d98000 + 26551248
    2   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    3   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 2:
    0   libsystem_kernel.dylib               0x00000001b4f2d30c semaphore_wait_trap + 8
    1   application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    2   application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    3   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    4   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 3:
    0   libsystem_kernel.dylib               0x00000001b4f2d2d0 mach_msg_trap + 8
    1   CoreFoundation                       0x0000000186f7cc30 __CFRunLoopServiceMachPort + 376
    2   CoreFoundation                       0x0000000186f76c14 __CFRunLoopRun + 1212
    3   CoreFoundation                       0x0000000186f7621c CFRunLoopRunSpecific + 596
    4   Foundation                           0x0000000188225df0 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228
    5   Foundation                           0x0000000188225cbc -[NSRunLoop(NSRunLoop) runUntilDate:] + 88
    6   UIKitCore                            0x0000000189a6ac48 -[UIEventFetcher threadMain] + 512
    7   Foundation                           0x0000000188397a34 __NSThread__start__ + 860
    8   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    9   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 4:
    0   libsystem_kernel.dylib               0x00000001b4f511ac __psynch_cvwait + 8
    1   application.iOS                      0x00000001066f9b60 0x104d98000 + 26614624
    2   application.iOS                      0x00000001066a00c4 0x104d98000 + 26247364
    3   application.iOS                      0x000000010669ff9c 0x104d98000 + 26247068
    4   application.iOS                      0x00000001066a01c0 0x104d98000 + 26247616
    5   application.iOS                      0x000000010668ef98 0x104d98000 + 26177432
    6   application.iOS                      0x0000000106609334 0x104d98000 + 25629492
    7   application.iOS                      0x0000000104eff558 0x104d98000 + 1471832
    8   application.iOS                      0x0000000104eff0c4 0x104d98000 + 1470660
    9   application.iOS                      0x0000000104efebcc 0x104d98000 + 1469388
    10  application.iOS                      0x0000000104efeb7c 0x104d98000 + 1469308
    11  application.iOS                      0x0000000104efe99c 0x104d98000 + 1468828
    12  application.iOS                      0x0000000104efeae8 0x104d98000 + 1469160
    13  application.iOS                      0x0000000104f01e14 0x104d98000 + 1482260
    14  application.iOS                      0x0000000104ef8d2c 0x104d98000 + 1445164
    15  application.iOS                      0x0000000104ef670c 0x104d98000 + 1435404
    16  application.iOS                      0x0000000104ef650c 0x104d98000 + 1434892
    17  application.iOS                      0x0000000104ef6490 0x104d98000 + 1434768
    18  application.iOS                      0x0000000104ef8e94 0x104d98000 + 1445524
    19  application.iOS                      0x0000000105178a00 0x104d98000 + 4065792
    20  application.iOS                      0x000000010658b33c 0x104d98000 + 25113404
    21  application.iOS                      0x0000000106646a60 0x104d98000 + 25881184
    22  application.iOS                      0x000000010664c34c 0x104d98000 + 25903948
    23  application.iOS                      0x0000000106694b44 0x104d98000 + 26200900
    24  application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    25  libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    26  libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 5:
    0   libsystem_kernel.dylib               0x00000001b4f2d2d0 mach_msg_trap + 8
    1   CoreFoundation                       0x0000000186f7cc30 __CFRunLoopServiceMachPort + 376
    2   CoreFoundation                       0x0000000186f76c14 __CFRunLoopRun + 1212
    3   CoreFoundation                       0x0000000186f7621c CFRunLoopRunSpecific + 596
    4   AudioSession                         0x000000018eabf0c4 GenericRunLoopThread::Entry(void*) + 160
    5   AudioSession                         0x000000018eac125c CAPThread::Entry(CAPThread*) + 88
    6   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    7   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 6:
    0   libsystem_kernel.dylib               0x00000001b4f2d2d0 mach_msg_trap + 8
    1   CoreFoundation                       0x0000000186f7cc30 __CFRunLoopServiceMachPort + 376
    2   CoreFoundation                       0x0000000186f76c14 __CFRunLoopRun + 1212
    3   CoreFoundation                       0x0000000186f7621c CFRunLoopRunSpecific + 596
    4   CFNetwork                            0x000000018784c1c0 _CFURLStorageSessionCopyCache + 64448
    5   Foundation                           0x0000000188397a34 __NSThread__start__ + 860
    6   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    7   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 7:
    0   libsystem_kernel.dylib               0x00000001b4f511ac __psynch_cvwait + 8
    1   application.iOS                      0x00000001066f9b88 0x104d98000 + 26614664
    2   application.iOS                      0x00000001066a00c4 0x104d98000 + 26247364
    3   application.iOS                      0x000000010669ff9c 0x104d98000 + 26247068
    4   application.iOS                      0x0000000106638db4 0x104d98000 + 25824692
    5   application.iOS                      0x0000000106607918 0x104d98000 + 25622808
    6   application.iOS                      0x0000000104ef8418 0x104d98000 + 1442840
    7   application.iOS                      0x0000000104ef84d0 0x104d98000 + 1443024
    8   application.iOS                      0x0000000104ef7fbc 0x104d98000 + 1441724
    9   application.iOS                      0x0000000104ef8010 0x104d98000 + 1441808
    10  application.iOS                      0x0000000104ef2ff8 0x104d98000 + 1421304
    11  application.iOS                      0x0000000104ef2d5c 0x104d98000 + 1420636
    12  application.iOS                      0x0000000105782750 0x104d98000 + 10397520
    13  application.iOS                      0x0000000105782548 0x104d98000 + 10397000
    14  application.iOS                      0x000000010578247c 0x104d98000 + 10396796
    15  application.iOS                      0x0000000105f43734 0x104d98000 + 18528052
    16  application.iOS                      0x0000000104ef8d2c 0x104d98000 + 1445164
    17  application.iOS                      0x0000000104ef670c 0x104d98000 + 1435404
    18  application.iOS                      0x0000000104ef650c 0x104d98000 + 1434892
    19  application.iOS                      0x0000000104ef6490 0x104d98000 + 1434768
    20  application.iOS                      0x0000000104ef8e94 0x104d98000 + 1445524
    21  application.iOS                      0x0000000105178a00 0x104d98000 + 4065792
    22  application.iOS                      0x000000010658b33c 0x104d98000 + 25113404
    23  application.iOS                      0x0000000106646a60 0x104d98000 + 25881184
    24  application.iOS                      0x000000010664c34c 0x104d98000 + 25903948
    25  application.iOS                      0x0000000106694b44 0x104d98000 + 26200900
    26  application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    27  libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    28  libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 8:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 9:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 10:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 11:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 12:
    0   libsystem_kernel.dylib               0x00000001b4f532b4 kevent_qos + 8
    1   libdispatch.dylib                    0x0000000186c15d4c _dispatch_kq_drain + 124
    2   libdispatch.dylib                    0x0000000186c1578c _dispatch_event_loop_poke + 160
    3   CFNetwork                            0x00000001876066dc 0x187600000 + 26332
    4   CFNetwork                            0x000000018760507c 0x187600000 + 20604
    5   CFNetwork                            0x000000018761e070 CFNetServiceBrowserSearchForServices + 76176
    6   CFNetwork                            0x000000018761df30 CFNetServiceBrowserSearchForServices + 75856
    7   CFNetwork                            0x0000000187601a88 0x187600000 + 6792
    8   CFNetwork                            0x00000001878640bc __CFTubeSetTubeTypeNotifier + 59180
    9   libdispatch.dylib                    0x0000000186bf424c _dispatch_call_block_and_release + 28
    10  libdispatch.dylib                    0x0000000186bf5db0 _dispatch_client_callout + 16
    11  libdispatch.dylib                    0x0000000186bfd10c _dispatch_lane_serial_drain + 576
    12  libdispatch.dylib                    0x0000000186bfdc90 _dispatch_lane_invoke + 456
    13  libdispatch.dylib                    0x0000000186c07d78 _dispatch_workloop_worker_thread + 704
    14  libsystem_pthread.dylib              0x00000001d2aad814 _pthread_wqthread + 272
    15  libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 13:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 14:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 15:
    0   libsystem_kernel.dylib               0x00000001b4f511ac __psynch_cvwait + 8
    1   application.iOS                      0x00000001066f9b60 0x104d98000 + 26614624
    2   application.iOS                      0x0000000106702840 0x104d98000 + 26650688
    3   application.iOS                      0x0000000106688c2c 0x104d98000 + 26151980
    4   application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    5   application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    6   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    7   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 16:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 17:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 18:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 19:
    0   libsystem_trace.dylib                0x000000019dddfa04 _os_log_impl_flatten_and_send + 1764
    1   libnetwork.dylib                     0x0000000187ab2c88 nw_endpoint_flow_setup_protocols + 3172
    2   libnetwork.dylib                     0x0000000187ab07cc nw_endpoint_flow_setup_channel + 2820
    3   libnetwork.dylib                     0x0000000187aacc00 -[NWConcrete_nw_endpoint_flow updatePathWithHandler:] + 3120
    4   libnetwork.dylib                     0x0000000187bafc50 nw_endpoint_handler_path_change + 14588
    5   libnetwork.dylib                     0x0000000187baada0 __nw_endpoint_handler_initialize_association_block_invoke + 152
    6   libnetwork.dylib                     0x0000000187d3788c __nw_association_update_paths_block_invoke.81 + 88
    7   libnetwork.dylib                     0x0000000187ee1b78 nw_hash_table_apply + 452
    8   libnetwork.dylib                     0x0000000187d371b0 nw_association_update_paths + 484
    9   libnetwork.dylib                     0x000000018803c508 nw_path_necp_update_evaluator + 2080
    10  libnetwork.dylib                     0x000000018803b9b8 nw_path_necp_check_for_updates + 1020
    11  libnetwork.dylib                     0x0000000188051f18 nw_path_evaluator_force_update + 124
    12  libnetwork.dylib                     0x0000000187d3f0b4 nw_association_force_update + 104
    13  libnetwork.dylib                     0x0000000187ab1b9c nw_endpoint_flow_setup_channel + 7892
    14  libnetwork.dylib                     0x0000000187abfe44 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 3732
    15  libnetwork.dylib                     0x0000000187bafc50 nw_endpoint_handler_path_change + 14588
    16  libnetwork.dylib                     0x0000000187bb6e14 nw_endpoint_handler_start + 1172
    17  libnetwork.dylib                     0x0000000187ee89b0 nw_endpoint_resolver_start_next_child + 4476
    18  libdispatch.dylib                    0x0000000186bf424c _dispatch_call_block_and_release + 28
    19  libdispatch.dylib                    0x0000000186bf5db0 _dispatch_client_callout + 16
    20  libdispatch.dylib                    0x0000000186bfef90 _dispatch_workloop_invoke + 1888
    21  libdispatch.dylib                    0x0000000186c07d78 _dispatch_workloop_worker_thread + 704
    22  libsystem_pthread.dylib              0x00000001d2aad814 _pthread_wqthread + 272
    23  libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 21:
    0   libsystem_kernel.dylib               0x00000001b4f51814 __semwait_signal + 8
    1   libsystem_c.dylib                    0x000000019042c5d4 usleep + 64
    2   AVFCore                              0x000000018ebf419c -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl _routePresentChanged] + 28
    3   Foundation                           0x0000000188249490 -[__NSObserver _doit:] + 344
    4   CoreFoundation                       0x0000000186f5e9a0 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 24
    5   CoreFoundation                       0x0000000186f5e948 ___CFXRegistrationPost_block_invoke + 48
    6   CoreFoundation                       0x0000000186f5deb0 _CFXRegistrationPost + 436
    7   CoreFoundation                       0x0000000186f5d870 _CFXNotificationPost + 712
    8   CoreFoundation                       0x0000000186f5e4a8 CFNotificationCenterPostNotificationWithOptions + 132
    9   CoreMedia                            0x000000018fe86ad8 CMNotificationCenterPostNotification + 124
    10  CoreMedia                            0x000000018ff4650c __figXPC_HandleNotificationMessage_block_invoke + 188
    11  libdispatch.dylib                    0x0000000186bf424c _dispatch_call_block_and_release + 28
    12  libdispatch.dylib                    0x0000000186bf5db0 _dispatch_client_callout + 16
    13  libdispatch.dylib                    0x0000000186bfd10c _dispatch_lane_serial_drain + 576
    14  libdispatch.dylib                    0x0000000186bfdc5c _dispatch_lane_invoke + 404
    15  libdispatch.dylib                    0x0000000186c07d78 _dispatch_workloop_worker_thread + 704
    16  libsystem_pthread.dylib              0x00000001d2aad814 _pthread_wqthread + 272
    17  libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 22:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 23:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 24:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 25:
    0   libsystem_kernel.dylib               0x00000001b4f52184 __workq_kernreturn + 8
    1   libsystem_pthread.dylib              0x00000001d2ab476c start_wqthread + 4
    
    Thread 26:
    0   application.iOS                      0x00000001065637bc 0x104d98000 + 24950716
    1   application.iOS                      0x000000010655e468 0x104d98000 + 24929384
    2   application.iOS                      0x000000010655f5d0 0x104d98000 + 24933840
    3   application.iOS                      0x000000010655ee0c 0x104d98000 + 24931852
    4   application.iOS                      0x00000001065865fc 0x104d98000 + 25093628
    5   application.iOS                      0x000000010658b050 0x104d98000 + 25112656
    6   application.iOS                      0x000000010664837c 0x104d98000 + 25887612
    7   application.iOS                      0x000000010664704c 0x104d98000 + 25882700
    8   application.iOS                      0x0000000106586658 0x104d98000 + 25093720
    9   application.iOS                      0x000000010658db30 0x104d98000 + 25123632
    10  application.iOS                      0x000000010658d650 0x104d98000 + 25122384
    11  application.iOS                      0x00000001051b602c 0x104d98000 + 4317228
    12  application.iOS                      0x0000000104faf348 0x104d98000 + 2192200
    13  application.iOS                      0x00000001060a3f70 0x104d98000 + 19971952
    14  application.iOS                      0x0000000104f0c4e0 0x104d98000 + 1524960
    15  application.iOS                      0x0000000104f0c1f4 0x104d98000 + 1524212
    16  application.iOS                      0x0000000104f0c468 0x104d98000 + 1524840
    17  application.iOS                      0x0000000104ef670c 0x104d98000 + 1435404
    18  application.iOS                      0x0000000104ef650c 0x104d98000 + 1434892
    19  application.iOS                      0x0000000104f10208 0x104d98000 + 1540616
    20  application.iOS                      0x0000000104f0c380 0x104d98000 + 1524608
    21  application.iOS                      0x0000000104f0c258 0x104d98000 + 1524312
    22  application.iOS                      0x0000000104efb818 0x104d98000 + 1456152
    23  application.iOS                      0x0000000105cc8ff0 0x104d98000 + 15929328
    24  application.iOS                      0x0000000104efd8d8 0x104d98000 + 1464536
    25  application.iOS                      0x0000000105178a00 0x104d98000 + 4065792
    26  application.iOS                      0x000000010658b33c 0x104d98000 + 25113404
    27  application.iOS                      0x000000010664837c 0x104d98000 + 25887612
    28  application.iOS                      0x000000010668b9c8 0x104d98000 + 26163656
    29  application.iOS                      0x00000001066892a4 0x104d98000 + 26153636
    30  application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    31  application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    32  libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    33  libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 27:
    0   libsystem_kernel.dylib               0x00000001b4f2d324 semaphore_timedwait_trap + 8
    1   application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    2   application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    3   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    4   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 28:
    0   libsystem_kernel.dylib               0x00000001b4f2d324 semaphore_timedwait_trap + 8
    1   application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    2   application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    3   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    4   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 29:
    0   libsystem_kernel.dylib               0x00000001b4f2d324 semaphore_timedwait_trap + 8
    1   application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    2   application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    3   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    4   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 30:
    0   libsystem_kernel.dylib               0x00000001b4f2d324 semaphore_timedwait_trap + 8
    1   application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    2   application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    3   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    4   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 31:
    0   libsystem_kernel.dylib               0x00000001b4f2d324 semaphore_timedwait_trap + 8
    1   application.iOS                      0x0000000106694a4c 0x104d98000 + 26200652
    2   application.iOS                      0x00000001066948d0 0x104d98000 + 26200272
    3   libsystem_pthread.dylib              0x00000001d2aabcb0 _pthread_start + 316
    4   libsystem_pthread.dylib              0x00000001d2ab4778 thread_start + 4
    
    Thread 20 crashed with arm64 Thread State:
       x21: 0x000000016c4530e0     x2: 0x0000000000000000    x16: 0x0000000000000148     x3: 0x0000000000000000
       x22: 0x00000001082059e0     x4: 0x00000000000001b0    x17: 0x000000016c453000   cpsr: 0x0000000040000000
        x5: 0x00000001082ada10    x23: 0x0000000109826848     x6: 0x0000000000000021    x18: 0x0000000000000000
       x10: 0x00000000000bcfa0     lr: 0x00000001d2aacb50     x7: 0x000000028307dc70    x24: 0x000000010a41acc8
       x11: 0x0000000000003fff     x8: 0x00000000000005b9    x19: 0x0000000000000006    x25: 0x00000001084698f8
        x9: 0x0d05def64a16a7e2    x12: 0x0000000108200000     fp: 0x000000016c4511b0    x26: 0x000000010887b000
       x13: 0x00000000cb5b701f     pc: 0x00000001b4f51414    x27: 0x0000000000000002    x14: 0x00000000cb5b6ff8
       x20: 0x0000000000014627     x0: 0x0000000000000000     sp: 0x000000016c451190    x28: 0x00000001051789ff
       x15: 0x00000000000027aa     x1: 0x0000000000000000
    
    Binary Images:
    0x0000000104d98000 -        0x000000010683ffff +application.iOS arm64  <4ff40b39b7f93b72b2e36f63c52b1e81> /private/var/containers/Bundle/Application/B99CA9E0-70E0-4203-9EA3-7EB8B6B892B1/application.iOS.app/application.iOS
    0x0000000186bf2000 -        0x0000000186c34fff  libdispatch.dylib arm64e  <b92757b104343e9ba3acb6da6b81945c> /usr/lib/system/libdispatch.dylib
    0x0000000186c35000 -        0x0000000186c6ffff  libdyld.dylib arm64e  <21b19919133438bcb233896e929945e0> /usr/lib/system/libdyld.dylib
    0x0000000186edc000 -        0x0000000187295fff  CoreFoundation arm64e  <727f2644eb4e3d57bc2ee6803ba92366> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
    0x0000000187600000 -        0x0000000187a97fff  CFNetwork arm64e  <0ebb3119a8ce35da96245b5528802fc8> /System/Library/Frameworks/CFNetwork.framework/CFNetwork
    0x0000000187a98000 -        0x00000001881a5fff  libnetwork.dylib arm64e  <39506b46189e3e828f32ab8326fcc2c7> /usr/lib/libnetwork.dylib
    0x000000018821d000 -        0x00000001884d8fff  Foundation arm64e  <7698bf3e0cf631c085e9562714f01276> /System/Library/Frameworks/Foundation.framework/Foundation
    0x0000000188dee000 -        0x000000018a29bfff  UIKitCore arm64e  <8518eae3832b3ff09fa59dbe3041f26c> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
    0x000000018eab2000 -        0x000000018eacafff  AudioSession arm64e  <ec9f661dcafc3a16b372bb4a803636e8> /System/Library/PrivateFrameworks/AudioSession.framework/AudioSession
    0x000000018eacb000 -        0x000000018ec6bfff  AVFCore arm64e  <0294540d081033fdbad051943cb01d86> /System/Library/PrivateFrameworks/AVFCore.framework/AVFCore
    0x000000018fe69000 -        0x000000018ff69fff  CoreMedia arm64e  <063231877fe13d2d9c430fdad845e776> /System/Library/Frameworks/CoreMedia.framework/CoreMedia
    0x00000001903b9000 -        0x0000000190437fff  libsystem_c.dylib arm64e  <961a8fb0de8a3567b4375d99cd549fae> /usr/lib/system/libsystem_c.dylib
    0x000000019ddd1000 -        0x000000019dde7fff  libsystem_trace.dylib arm64e  <3520924c65a7351dadbea07268a9bca7> /usr/lib/system/libsystem_trace.dylib
    0x000000019eb3d000 -        0x000000019eb45fff  GraphicsServices arm64e  <1959c615fa0830de8461884a5bbc8037> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
    0x00000001b4f29000 -        0x00000001b4f5afff  libsystem_kernel.dylib arm64e  <b373b97b671e301ca6b7c9f92e17dca0> /usr/lib/system/libsystem_kernel.dylib
    0x00000001d2aaa000 -        0x00000001d2ab5fff  libsystem_pthread.dylib arm64e  <c939a2abd3b13b0a83c57ce2f4f339a9> /usr/lib/system/libsystem_pthread.dylib
    
  9. mandel-macaque commented on Jun 4, 2021

    @mandel-macaque
    Contributor

    @adams-family so, from the version you have in the App Store, you have 14.14.2.5 with hash 3836759, looking in the repo, the code of that version points to https://github.com/xamarin/xamarin-macios/blob/3836759d4/src/Foundation/NSUrlSessionHandler.cs#L543 which does not have the fix. Please update and get back to us.

  10. adams-family commented on Jun 4, 2021

    @adams-family
    Author

    @mandel-macaque Got it! Updating and will push a new version to the AppStore. I should know in about it week if it helped.

  11. added
    need-info
    on Jun 4, 2021
  12. 61 remaining items

  13. csnellemann commented on Jan 26, 2024

    @csnellemann

    @hjharvey-MSFT any update on this, given the hypothesis from @TimofeyBurak above?

  14. kmiterror commented on Feb 14, 2024

    @kmiterror

    This is still a thing, we are getting tons of those after updating to net7.
    We changed default HttpClient implementation to use HttpClient (managed) handler, but it seems that one of our sub-dependencies doesn't respect that setting.

  15. tipa commented on Mar 11, 2024

    @tipa

    I was able to reproduce the crash locally 4 times within just a couple of minutes using this example:
    nsurlsessionhandler.zip

    2024-03-11 12:14:44.122321+0100 nsurlsessionhandler[15973:365565] *** Terminating app due to uncaught exception 'System.ObjectDisposedException', reason: 'The CancellationTokenSource has been disposed. (System.ObjectDisposedException)
       at System.Threading.CancellationTokenSource.ThrowIfDisposed()
       at System.Threading.CancellationTokenSource.get_Token()
       at System.Net.Http.NSUrlSessionHandler.NSUrlSessionHandlerDelegate.SetResponse(InflightData inflight) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 965
       at System.Net.Http.NSUrlSessionHandler.NSUrlSessionHandlerDelegate.DidReceiveData(NSUrlSession session, NSUrlSessionDataTask dataTask, NSData data) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 927
    '
    *** First throw call stack:
    (
    	0   CoreFoundation                      0x000000010ea86761 __exceptionPreprocess + 242
    	1   libobjc.A.dylib                     0x000000011ef2e904 objc_exception_throw + 48
    	2   libxamarin-dotnet-debug.dylib       0x0000000109eb9016 xamarin_process_ma
    *** Terminating app due to uncaught exception 'System.ObjectDisposedException', reason: 'The CancellationTokenSource has been disposed. (System.ObjectDisposedException)
       at System.Threading.CancellationTokenSource.ThrowIfDisposed()
       at System.Threading.CancellationTokenSource.get_Token()
       at System.Net.Http.NSUrlSessionHandler.NSUrlSessionHandlerDelegate.SetResponse(InflightData inflight) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 965
       at System.Net.Http.NSUrlSessionHandler.NSUrlSessionHandlerDelegate.DidReceiveData(NSUrlSession session, NSUrlSessionDataTask dataTask, NSData data) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 927
    '
    *** First throw call stack:
    (
    	0   CoreFoundation                      0x000000010ea86761 __exceptionPreprocess + 242
    	1   libobjc.A.dylib                     0x000000011ef2e904 objc_exception_throw + 48
    	2   libxamarin-dotnet-debug.dylib       0x0000000109eb9016 xamarin_process_managed_exception + 934
    	3   nsurlsessionhandler                 0x000000010014ed67 _ZL31native_to_managed_trampoline_59P11objc_objectP13objc_selectorPP11_MonoMethodS0_S0_S0_j + 1143
    	4   nsurlsessionhandler                 0x0000000100176713 -[System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate URLSession:dataTask:didReceiveData:] + 67
    	5   CFNetwork                           0x000000010bd4ea69 CFNetwork + 72297
    	6   libdispatch.dylib                   0x000000011f39ca90 _dispatch_call_block_and_release + 12
    	7   libdispatch.dylib                   0x000000011f39dd3a _dispatch_client_callout + 8
    	8   libdispatch.dylib                   0x000000011f3a585c _dispatch_lane_serial_drain + 1236
    	9   libdispatch.dylib                   0x000000011f3a63f7 _dispatch_lane_invoke + 406
    	10  libdispatch.dylib                   0x000000011f3b1fac _dispatch_root_queue_drain_deferred_wlh + 276
    	11  libdispatch.dylib                   0x000000011f3b1572 _dispatch_workloop_worker_thread + 552
    	12  libsystem_pthread.dylib             0x0000000120341c47 _pthread_wqthread + 327
    	13  libsystem_pthread.dylib             0x0000000120340b97 start_wqthread + 15
    
    

    I also noticed several of those logs, which appear to be unrelated, but perhaps should be addressed as well:

    2024-03-11 12:15:58.090531+0100 nsurlsessionhandler[16022:367058] [API] API MISUSE: NSURLSession delegate System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate: <System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate: 0x600000c05d20> (0x600000c05d20)
    2024-03-11 12:15:58.092269+0100 nsurlsessionhandler[16022:367058] [API] API MISUSE: dataTask:didReceiveResponse:completionHandler: completion handler not called
    
  16. rolfbjarne commented on Mar 12, 2024

    @rolfbjarne
    Member

    I was able to reproduce the crash locally 4 times within just a couple of minutes using this example:

    I can reproduce crashes too. I'll have a look.

  17. rolfbjarne commented on Mar 15, 2024

    @rolfbjarne
    Member

    It seems this is the sequence of events for the ObjectDisposedException:

    1. The request is sent.
    2. The request is cancelled.
    3. The InflightData instance is removed here: https://github.com/xamarin/xamarin-macios/blob/c3437328bf2c02d03a6d4dc4e752ef8ac927ca4e/src/Foundation/NSUrlSessionHandler.cs#L545
      3a. The InflightData is disposed: https://github.com/xamarin/xamarin-macios/blob/c3437328bf2c02d03a6d4dc4e752ef8ac927ca4e/src/Foundation/NSUrlSessionHandler.cs#L224
      3a. The InflightData.CancellationTokenSource instance is disposed: https://github.com/xamarin/xamarin-macios/blob/c3437328bf2c02d03a6d4dc4e752ef8ac927ca4e/src/Foundation/NSUrlSessionHandler.cs#L1168
    4. Data comes in (in the DidReceiveData callback), and SetResponse is called: https://github.com/xamarin/xamarin-macios/blob/c3437328bf2c02d03a6d4dc4e752ef8ac927ca4e/src/Foundation/NSUrlSessionHandler.cs#L932
      4a. The SetResponse method tries to use InflightData.CancellationTokenSource, and that throws an ObjectDisposedException: https://github.com/xamarin/xamarin-macios/blob/c3437328bf2c02d03a6d4dc4e752ef8ac927ca4e/src/Foundation/NSUrlSessionHandler.cs#L970

    Full stack traces:

    Inflight disposed:
       at System.Net.Http.NSUrlSessionHandler.InflightData.Dispose(Boolean disposing) in xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 1168
       at System.Net.Http.NSUrlSessionHandler.InflightData.Dispose() in xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 1160
       at System.Net.Http.NSUrlSessionHandler.RemoveInflightData(NSUrlSessionTask task, Boolean cancel) in xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 224
       at System.Net.Http.NSUrlSessionHandler.<>c__DisplayClass58_0.<SendAsync>b__0() in xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 545
       at System.Threading.CancellationToken.<>c.<Register>b__12_0(Object obj)
       at System.Threading.CancellationTokenSource.Invoke(Delegate d, Object state, CancellationTokenSource source)
       at System.Threading.CancellationTokenSource.CallbackNode.<>c.<ExecuteCallback>b__9_0(Object s)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback()
       at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
       at System.Threading.CancellationTokenSource.NotifyCancellation(Boolean throwOnFirstException)
       at System.Threading.CancellationTokenSource.LinkedNCancellationTokenSource.<>c.<.cctor>b__4_0(Object s)
       at System.Threading.CancellationTokenSource.Invoke(Delegate d, Object state, CancellationTokenSource source)
       at System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback()
       at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
       at System.Threading.CancellationTokenSource.NotifyCancellation(Boolean throwOnFirstException)
       at System.Threading.CancellationTokenSource.TimerCallback(Object state)
       at System.Threading.TimerQueueTimer.CallCallback(Boolean isThreadPool)
       at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
       at System.Threading.TimerQueue.FireNextTimers()
       at System.Threading.TimerQueue.System.Threading.IThreadPoolWorkItem.Execute()
       at System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object workItem, Thread currentThread)
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
       at System.Threading.Thread.StartCallback()
    
    ObjectDisposedException:
       *** Terminating app due to uncaught exception 'System.ObjectDisposedException', reason: 'The CancellationTokenSource has been disposed. (System.ObjectDisposedException)
          at System.Net.Http.NSUrlSessionHandler.NSUrlSessionHandlerDelegate.SetResponse(InflightData inflight) in xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 970
          at System.Net.Http.NSUrlSessionHandler.NSUrlSessionHandlerDelegate.DidReceiveData(NSUrlSession session, NSUrlSessionDataTask dataTask, NSData data) in xamarin-macios/src/Foundation/NSUrlSessionHandler.cs:line 932
       '
       *** First throw call stack:
       (
          0   CoreFoundation                      0x0000000186e72ccc __exceptionPreprocess + 176
          1   libobjc.A.dylib                     0x000000018695a788 objc_exception_throw + 60
          2   nsurlsessionhandler                 0x0000000106d4562c xamarin_process_managed_exception + 1052
          3   nsurlsessionhandler                 0x00000001071a26c4 _ZL31native_to_managed_trampoline_53P11objc_objectP13objc_selectorPP11_MonoMethodS0_S0_S0_j + 1028
          4   nsurlsessionhandler                 0x00000001071ca8e0 -[System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate URLSession:dataTask:didReceiveData:] + 68
          5   CFNetwork                           0x000000018c0fe28c CFURLCredentialStorageCopyAllCredentials + 61900
          6   libdispatch.dylib                   0x0000000186b6c750 _dispatch_call_block_and_release + 32
          7   libdispatch.dylib                   0x0000000186b6e3e8 _dispatch_client_callout + 20
          8   libdispatch.dylib                   0x0000000186b75a14 _dispatch_lane_serial_drain + 748
          9   libdispatch.dylib                   0x0000000186b76578 _dispatch_lane_invoke + 432
          10  libdispatch.dylib                   0x0000000186b812d0 _dispatch_root_queue_drain_deferred_wlh + 288
          11  libdispatch.dylib                   0x0000000186b80b44 _dispatch_workloop_worker_thread + 404
          12  libsystem_pthread.dylib             0x0000000186d1b00c _pthread_wqthread + 288
          13  libsystem_pthread.dylib             0x0000000186d19d28 start_wqthread + 8
    

    @mandel-macaque it seems an easy fix would be to just not dispose the CancellationTokenSource, the GC will eventually do it.

    Although MSDN says quite clearly:

    Always call Dispose before you release your last reference to the CancellationTokenSource. Otherwise, the resources it is using will not be freed until the garbage collector calls the CancellationTokenSource object's Finalize method.

    The amount of entry points into this code makes it quite complex to keep it
    thread-safe, while at the same time not accidentally not run into deadlocks.
    While disposing the CancellationTokenSource would be ideal, the additional
    complexity this would entail makes me question whether it's worth it.

  18. rolfbjarne commented on Mar 18, 2024

    @rolfbjarne
    Member

    I also noticed several of those logs, which appear to be unrelated, but perhaps should be addressed as well:

    2024-03-11 12:15:58.090531+0100 nsurlsessionhandler[16022:367058] [API] API MISUSE: NSURLSession delegate System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate: <System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate: 0x600000c05d20> (0x600000c05d20)
    2024-03-11 12:15:58.092269+0100 nsurlsessionhandler[16022:367058] [API] API MISUSE: dataTask:didReceiveResponse:completionHandler: completion handler not called
    

    Fix in progress: #20326.

  19. added a commit that references this issue on Mar 18, 2024
    2290fad
  20. added
    networking
    on Mar 18, 2024
  21. added a commit that references this issue on Mar 19, 2024
    ab3fc14
  22. kmiterror commented on Apr 19, 2024

    @kmiterror

    @rolfbjarne
    Is this going to be backported to dotnet8?

  23. rolfbjarne commented on Apr 19, 2024

    @rolfbjarne
    Member

    @rolfbjarne Is this going to be backported to dotnet8?

    The networking code is rather sensitive, in that any changes has a high potential for breaking someone. Coupled with the fact that these changes weren't entirely trivial, at the moment we're leaning towards not backporting them to .NET 8.

    However, these changes are included in .NET 9 preview 3, so if you want to try the preview, and see if your issues are fixed, then that would be great (and a successful test might also make us reconsider backporting the fixes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugiOSmobcatnetworkingsupport

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions