Skip to content

Crash in networking stack #20345

Description

@rolfbjarne

Use this test project: #11799 (comment)

Run the project for a while (typically hours, sometimes overnight - at one point it crashed after 16 hours / just over 1.5M network requests), and it eventually crashes.

lldb shows this stack trace:

(lldb) bt
* thread #1, name = 'tid_103', queue = 'com.apple.main-thread', stop reason = signal SIGSEGV
  * frame #0: 0x000000019d9e5c34 libobjc.A.dylib`objc_msgSend + 52
    frame #1: 0x000000019da18a5c libobjc.A.dylib`objc_object::sidetable_release(bool, bool) + 292
    frame #2: 0x00000001a30f169c CFNetwork`___lldb_unnamed_symbol2909 + 32
    frame #3: 0x00000001a30f1400 CFNetwork`___lldb_unnamed_symbol2903 + 260
    frame #4: 0x000000019dab717c libsystem_blocks.dylib`_call_dispose_helpers_excp + 48
    frame #5: 0x000000019dab6f48 libsystem_blocks.dylib`_Block_release + 252
    frame #6: 0x00000001a3194e7c CFNetwork`___lldb_unnamed_symbol5273 + 28
    frame #7: 0x000000019dab717c libsystem_blocks.dylib`_call_dispose_helpers_excp + 48
    frame #8: 0x000000019dab6f48 libsystem_blocks.dylib`_Block_release + 252
    frame #9: 0x000000019dc0a3e8 libdispatch.dylib`_dispatch_client_callout + 20
    frame #10: 0x000000019dc18bb8 libdispatch.dylib`_dispatch_main_queue_drain + 988
    frame #11: 0x000000019dc187cc libdispatch.dylib`_dispatch_main_queue_callback_4CF + 44
    frame #12: 0x000000019dedb4ac CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
    frame #13: 0x000000019de98c30 CoreFoundation`__CFRunLoopRun + 1996
    frame #14: 0x000000019de97e0c CoreFoundation`CFRunLoopRunSpecific + 608
    frame #15: 0x00000001a8633000 HIToolbox`RunCurrentEventLoopInMode + 292
    frame #16: 0x00000001a8632e3c HIToolbox`ReceiveNextEventCommon + 648
    frame #17: 0x00000001a8632b94 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 76
    frame #18: 0x00000001a16f0970 AppKit`_DPSNextEvent + 660
    frame #19: 0x00000001a1ee2dec AppKit`-[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700
    frame #20: 0x00000001a16e3cb8 AppKit`-[NSApplication run] + 476
    frame #21: 0x00000001a16baf54 AppKit`NSApplicationMain + 880
    frame #22: 0x00000001a190d610 AppKit`_NSApplicationMainWithInfoDictionary + 24
    frame #23: 0x00000001b71290dc UIKitMacHelper`UINSApplicationMain + 972
    frame #24: 0x00000001cd2159b4 UIKitCore`UIApplicationMain + 148
    frame #25: 0x0000000106879854 nsurlsessionhandler`xamarin_UIApplicationMain(argc=0, argv=0x00006000028144c0, principalClassName=0x0000000000000000, delegateClassName="AppDelegate", exception_gchandle=0x000000016fdfe8e0) at bindings.m:126:10
    frame #26: 0x00000001065c6280 nsurlsessionhandler`wrapper_managed_to_native_UIKit_UIApplication_xamarin_UIApplicationMain_int_intptr_intptr_intptr_intptr_ + 176
    frame #27: 0x0000000105db9614 nsurlsessionhandler`UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 100
    frame #28: 0x0000000105db9948 nsurlsessionhandler`UIKit_UIApplication_Main_string___System_Type_System_Type + 280
    frame #29: 0x0000000102492d68 nsurlsessionhandler`Program__Main__string__ + 136
    frame #30: 0x000000010508ea08 nsurlsessionhandler`wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 296
    frame #31: 0x0000000106b8ea90 nsurlsessionhandler`mono_jit_runtime_invoke(method=<unavailable>, obj=<unavailable>, params=<unavailable>, exc=<unavailable>, error=0x000000016fdfec90) at mini-runtime.c:3636:3 [opt]
    frame #32: 0x0000000106b2f158 nsurlsessionhandler`mono_runtime_invoke_checked [inlined] do_runtime_invoke(method=0x000000011a914598, obj=0x0000000000000000, params=0x000000016fdfec30, exc=0x0000000000000000, error=0x000000016fdfec90) at object.c:2576:11 [opt]
    frame #33: 0x0000000106b2f11c nsurlsessionhandler`mono_runtime_invoke_checked(method=0x000000011a914598, obj=0x0000000000000000, params=0x000000016fdfec30, error=0x000000016fdfec90) at object.c:2792:9 [opt]
    frame #34: 0x0000000106b35494 nsurlsessionhandler`mono_runtime_exec_main_checked [inlined] do_exec_main_checked(method=0x000000011a914598, args=<unavailable>, error=0x000000016fdfec90) at object.c:0 [opt]
    frame #35: 0x0000000106b35458 nsurlsessionhandler`mono_runtime_exec_main_checked(method=0x000000011a914598, args=<unavailable>, error=0x000000016fdfec90) at object.c:4775:9 [opt]
    frame #36: 0x0000000106b35540 nsurlsessionhandler`mono_runtime_run_main_checked(method=<unavailable>, argc=<unavailable>, argv=<unavailable>, error=<unavailable>) at object.c:4339:9 [opt] [artificial]
    frame #37: 0x0000000106be1434 nsurlsessionhandler`mono_jit_exec at driver.c:1369:13 [opt]
    frame #38: 0x0000000106be1424 nsurlsessionhandler`mono_jit_exec(domain=<unavailable>, assembly=<unavailable>, argc=1, argv=0x000000016fdfed10) at driver.c:1314:7 [opt]
    frame #39: 0x00000001068a2e58 nsurlsessionhandler`xamarin_main(argc=1, argv=0x000000016fdff070, launch_mode=XamarinLaunchModeApp) at monotouch-main.m:495:8
    frame #40: 0x0000000106d47b18 nsurlsessionhandler`main(argc=1, argv=0x000000016fdff070) at main.arm64.mm:416:11
    frame #41: 0x000000019da320e0 dyld`start + 2360

manually symbolicating the stack using backtrace in lldb shows:

(lldb) parray 20 (char **) 0x000000011aa14800
(char **) $1 = 0x000000011aa14800 {
  [0] = 0x000000011aa148a0 "0   ???                                 0x000000010f58c64c 0x0 + 4552443468"
  [1] = 0x000000011aa148ec "1   nsurlsessionhandler                 0x0000000106d47ad8 main + 0"
  [2] = 0x000000011aa14930 "2   CFNetwork                           0x00000001a30f169c CFURLRequestGetMainDocumentURL + 20720"
  [3] = 0x000000011aa14992 "3   CFNetwork                           0x00000001a30f1400 CFURLRequestGetMainDocumentURL + 20052"
  [4] = 0x000000011aa149f4 "4   libsystem_blocks.dylib              0x000000019dab717c _call_dispose_helpers_excp + 48"
  [5] = 0x000000011aa14a4f "5   libsystem_blocks.dylib              0x000000019dab6f48 _Block_release + 252"
  [6] = 0x000000011aa14a9f "6   CFNetwork                           0x00000001a3194e7c CFURLCredentialStorageCopyAllCredentials + 40380"
  [7] = 0x000000011aa14b0b "7   libsystem_blocks.dylib              0x000000019dab717c _call_dispose_helpers_excp + 48"
  [8] = 0x000000011aa14b66 "8   libsystem_blocks.dylib              0x000000019dab6f48 _Block_release + 252"
  [9] = 0x000000011aa14bb6 "9   libdispatch.dylib                   0x000000019dc0a3e8 _dispatch_client_callout + 20"
  [10] = 0x000000011aa14c0f "10  libdispatch.dylib                   0x000000019dc18bb8 _dispatch_main_queue_drain + 988"
  [11] = 0x000000011aa14c6b "11  libdispatch.dylib                   0x000000019dc187cc _dispatch_main_queue_callback_4CF + 44"
  [12] = 0x000000011aa14ccd "12  CoreFoundation                      0x000000019dedb4ac __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16"
  [13] = 0x000000011aa14d40 "13  CoreFoundation                      0x000000019de98c30 __CFRunLoopRun + 1996"
  [14] = 0x000000011aa14d91 "14  CoreFoundation                      0x000000019de97e0c CFRunLoopRunSpecific + 608"
  [15] = 0x000000011aa14de7 "15  HIToolbox                           0x00000001a8633000 RunCurrentEventLoopInMode + 292"
  [16] = 0x000000011aa14e42 "16  HIToolbox                           0x00000001a8632e3c ReceiveNextEventCommon + 648"
  [17] = 0x000000011aa14e9a "17  HIToolbox                           0x00000001a8632b94 _BlockUntilNextEventMatchingListInModeWithFilter + 76"
  [18] = 0x000000011aa14f0b "18  AppKit                              0x00000001a16f0970 _DPSNextEvent + 660"
  [19] = 0x000000011aa14f5a "19  AppKit                              0x00000001a1ee2dec -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700"
}

Some investigation in lldb revelead:

  • ___lldb_unnamed_symbol2909: [__NSCFURLSessionConnection dealloc]
  • ___lldb_unnamed_symbol2903: [__NSCFURLLocalSessionConnection dealloc]
  • ___lldb_unnamed_symbol5273: a block dispose method

Some more lldb info:


(lldb) disass
CFNetwork`___lldb_unnamed_symbol2909: # [__NSCFURLSessionConnection dealloc]
    0x1a30f167c <+0>:   pacibsp
    0x1a30f1680 <+4>:   sub    sp, sp, #0x30
    0x1a30f1684 <+8>:   stp    x20, x19, [sp, #0x10]
    0x1a30f1688 <+12>:  stp    x29, x30, [sp, #0x20]
    0x1a30f168c <+16>:  add    x29, sp, #0x20
    0x1a30f1690 <+20>:  mov    x19, x0
    0x1a30f1694 <+24>:  ldr    x0, [x0, #0x8]
    0x1a30f1698 <+28>:  bl     0x1a3359158               ; symbol stub for: objc_release
->  0x1a30f169c <+32>:  ldr    x0, [x19, #0x10]
    0x1a30f16a0 <+36>:  cbz    x0, 0x1a30f16ac           ; <+48>
    0x1a30f16a4 <+40>:  bl     0x1a3357578               ; symbol stub for: dispatch_release
    0x1a30f16a8 <+44>:  str    xzr, [x19, #0x10]
    0x1a30f16ac <+48>:  mov    x0, x19
    0x1a30f16b0 <+52>:  mov    x2, #0x0
    0x1a30f16b4 <+56>:  mov    w3, #0x18
    0x1a30f16b8 <+60>:  bl     0x1a33591c8               ; symbol stub for: objc_setProperty_atomic
    0x1a30f16bc <+64>:  ldr    x0, [x19, #0x28]
    0x1a30f16c0 <+68>:  cbz    x0, 0x1a30f16cc           ; <+80>
    0x1a30f16c4 <+72>:  bl     0x1a3359158               ; symbol stub for: objc_release
    0x1a30f16c8 <+76>:  str    xzr, [x19, #0x28]
    0x1a30f16cc <+80>:  ldr    x0, [x19, #0x30]
    0x1a30f16d0 <+84>:  cbz    x0, 0x1a30f16dc           ; <+96>
    0x1a30f16d4 <+88>:  bl     0x1a3357578               ; symbol stub for: dispatch_release
    0x1a30f16d8 <+92>:  str    xzr, [x19, #0x30]
    0x1a30f16dc <+96>:  adrp   x8, 424846
    0x1a30f16e0 <+100>: ldr    x8, [x8, #0x890]
    0x1a30f16e4 <+104>: stp    x19, x8, [sp]
    0x1a30f16e8 <+108>: adrp   x8, 373089
    0x1a30f16ec <+112>: add    x1, x8, #0x71f
    0x1a30f16f0 <+116>: mov    x0, sp
    0x1a30f16f4 <+120>: bl     0x1a33590f8               ; symbol stub for: objc_msgSendSuper2
    0x1a30f16f8 <+124>: ldp    x29, x30, [sp, #0x20]
    0x1a30f16fc <+128>: ldp    x20, x19, [sp, #0x10]
    0x1a30f1700 <+132>: add    sp, sp, #0x30
    0x1a30f1704 <+136>: retab


(lldb) disass
CFNetwork`___lldb_unnamed_symbol2903: # [__NSCFURLLocalSessionConnection dealloc]
    0x1a30f12fc <+0>:   pacibsp
    0x1a30f1300 <+4>:   sub    sp, sp, #0x30
    0x1a30f1304 <+8>:   stp    x20, x19, [sp, #0x10]
    0x1a30f1308 <+12>:  stp    x29, x30, [sp, #0x20]
    0x1a30f130c <+16>:  add    x29, sp, #0x20
    0x1a30f1310 <+20>:  mov    x19, x0
    0x1a30f1314 <+24>:  adrp   x8, 399283
    0x1a30f1318 <+28>:  ldrsw  x20, [x8, #0x414]
    0x1a30f131c <+32>:  ldr    x0, [x0, x20]
    0x1a30f1320 <+36>:  cbz    x0, 0x1a30f134c           ; <+80>
    0x1a30f1324 <+40>:  ldr    x16, [x0]
    0x1a30f1328 <+44>:  mov    x17, x0
    0x1a30f132c <+48>:  movk   x17, #0x81be, lsl #48
    0x1a30f1330 <+52>:  autda  x16, x17
    0x1a30f1334 <+56>:  ldr    x8, [x16, #0x8]!
    0x1a30f1338 <+60>:  mov    x9, x16
    0x1a30f133c <+64>:  mov    x17, x9
    0x1a30f1340 <+68>:  movk   x17, #0x990e, lsl #48
    0x1a30f1344 <+72>:  blraa  x8, x17
    0x1a30f1348 <+76>:  str    xzr, [x19, x20]
    0x1a30f134c <+80>:  adrp   x8, 399283
    0x1a30f1350 <+84>:  ldrsw  x20, [x8, #0x410]
    0x1a30f1354 <+88>:  ldr    x0, [x19, x20]
    0x1a30f1358 <+92>:  cbz    x0, 0x1a30f1384           ; <+136>
    0x1a30f135c <+96>:  ldr    x16, [x0]
    0x1a30f1360 <+100>: mov    x17, x0
    0x1a30f1364 <+104>: movk   x17, #0x4399, lsl #48
    0x1a30f1368 <+108>: autda  x16, x17
    0x1a30f136c <+112>: ldr    x8, [x16, #0x8]!
    0x1a30f1370 <+116>: mov    x9, x16
    0x1a30f1374 <+120>: mov    x17, x9
    0x1a30f1378 <+124>: movk   x17, #0x3f8b, lsl #48
    0x1a30f137c <+128>: blraa  x8, x17
    0x1a30f1380 <+132>: str    xzr, [x19, x20]
    0x1a30f1384 <+136>: adrp   x8, 399283
    0x1a30f1388 <+140>: ldrsw  x20, [x8, #0x41c]
    0x1a30f138c <+144>: ldr    x0, [x19, x20]
    0x1a30f1390 <+148>: cbz    x0, 0x1a30f139c           ; <+160>
    0x1a30f1394 <+152>: bl     0x1a3359158               ; symbol stub for: objc_release
    0x1a30f1398 <+156>: str    xzr, [x19, x20]
    0x1a30f139c <+160>: adrp   x8, 399283
    0x1a30f13a0 <+164>: ldrsw  x20, [x8, #0x420]
    0x1a30f13a4 <+168>: ldr    x0, [x19, x20]
    0x1a30f13a8 <+172>: cbz    x0, 0x1a30f13b4           ; <+184>
    0x1a30f13ac <+176>: bl     0x1a3357578               ; symbol stub for: dispatch_release
    0x1a30f13b0 <+180>: str    xzr, [x19, x20]
    0x1a30f13b4 <+184>: adrp   x8, 399283
    0x1a30f13b8 <+188>: ldrsw  x20, [x8, #0x424]
    0x1a30f13bc <+192>: ldr    x0, [x19, x20]
    0x1a30f13c0 <+196>: cbz    x0, 0x1a30f13cc           ; <+208>
    0x1a30f13c4 <+200>: bl     0x1a3357578               ; symbol stub for: dispatch_release
    0x1a30f13c8 <+204>: str    xzr, [x19, x20]
    0x1a30f13cc <+208>: adrp   x8, 399283
    0x1a30f13d0 <+212>: ldrsw  x20, [x8, #0x428]
    0x1a30f13d4 <+216>: ldr    x0, [x19, x20]
    0x1a30f13d8 <+220>: cbz    x0, 0x1a30f13e4           ; <+232>
    0x1a30f13dc <+224>: bl     0x1a3359158               ; symbol stub for: objc_release
    0x1a30f13e0 <+228>: str    xzr, [x19, x20]
    0x1a30f13e4 <+232>: adrp   x8, 424846
    0x1a30f13e8 <+236>: ldr    x8, [x8, #0x898]
    0x1a30f13ec <+240>: stp    x19, x8, [sp]
    0x1a30f13f0 <+244>: adrp   x8, 373089
    0x1a30f13f4 <+248>: add    x1, x8, #0x71f
    0x1a30f13f8 <+252>: mov    x0, sp
    0x1a30f13fc <+256>: bl     0x1a33590f8               ; symbol stub for: objc_msgSendSuper2
->  0x1a30f1400 <+260>: ldp    x29, x30, [sp, #0x20]
    0x1a30f1404 <+264>: ldp    x20, x19, [sp, #0x10]
    0x1a30f1408 <+268>: add    sp, sp, #0x30
    0x1a30f140c <+272>: retab

(lldb) disass
CFNetwork`___lldb_unnamed_symbol5273: # block dispose method
    0x1a3194e60 <+0>:  pacibsp
    0x1a3194e64 <+4>:  stp    x20, x19, [sp, #-0x20]!
    0x1a3194e68 <+8>:  stp    x29, x30, [sp, #0x10]
    0x1a3194e6c <+12>: add    x29, sp, #0x10
    0x1a3194e70 <+16>: mov    x19, x0
    0x1a3194e74 <+20>: ldr    x0, [x0, #0x30]
    0x1a3194e78 <+24>: bl     0x1a3359158               ; symbol stub for: objc_release
->  0x1a3194e7c <+28>: ldr    x0, [x19, #0x28]
    0x1a3194e80 <+32>: bl     0x1a3359158               ; symbol stub for: objc_release
    0x1a3194e84 <+36>: ldr    x0, [x19, #0x20]
    0x1a3194e88 <+40>: ldp    x29, x30, [sp, #0x10]
    0x1a3194e8c <+44>: ldp    x20, x19, [sp], #0x20
    0x1a3194e90 <+48>: autibsp
    0x1a3194e94 <+52>: eor    x16, x30, x30, lsl #1
    0x1a3194e98 <+56>: tbz    x16, #0x3e, 0x1a3194ea0   ; <+64>
    0x1a3194e9c <+60>: brk    #0xc471
    0x1a3194ea0 <+64>: b      0x1a3359158               ; symbol stub for: objc_release

(lldb) re re
General Purpose Registers:
        x0 = 0x000000011b8b5180
        x1 = 0x00000001fe25271f
        x2 = 0x0000600003fbe3c0
        x3 = 0x0000600003fbe3c0
        x4 = 0x0000600003fbe440
        x5 = 0x00000000000023c0
        x6 = 0x0000000000000000
        x7 = 0x0000000000000403
        x8 = 0x000000020a5f4e78  "dealloc"
        x9 = 0x000000020a5f4e78  "dealloc"
       x10 = 0x0000000400000041
       x11 = 0x0000000000000000
       x12 = 0x0000000000000000
       x13 = 0x0000000400000041
       x14 = 0x000000011b893ce0
       x15 = 0x000000011b893ce0
       x16 = 0x000000011b893ce0
       x17 = 0x0000000000000001
       x18 = 0x0000000000000000
       x19 = 0x000000011b8b5180
       x20 = 0x0000000000000001
       x21 = 0x0000000205ac7400  libobjc.A.dylib`(anonymous namespace)::SideTablesMap + 3072
       x22 = 0x0000000000000001
       x23 = 0x0000000000000104
       x24 = 0x0000000000000000
       x25 = 0x0000000205ac7ba0  dyld`_main_thread + 224
       x26 = 0x0000600003fbd100
       x27 = 0x000000000000000f
       x28 = 0x0000000000000000
        fp = 0x000000016fdfcea0
        lr = 0x000000019da18a5c  libobjc.A.dylib`objc_object::sidetable_release(bool, bool) + 292
        sp = 0x000000016fdfce50
        pc = 0x000000019d9e5c34  libobjc.A.dylib`objc_msgSend + 52
      cpsr = 0x20001000

Activity

  1. added
    bug
    networking
    on Mar 20, 2024
  2. added this to the Future milestone on Mar 20, 2024
  3. tipa commented on Oct 2, 2024

    @tipa
  4. rolfbjarne commented on Oct 2, 2024

    @rolfbjarne
    Author
  5. sleushunou commented on Feb 28, 2025

    @sleushunou
  6. rolfbjarne commented on Feb 28, 2025

    @rolfbjarne
    Author
  7. mlancione commented on Apr 22, 2025

    @mlancione

    Any update on this issue? We are experiencing the same issue even when running the latest .NET 9 release (9.0.203 iOS 18.4.9288).

    Thread 0 Crashed:
    0 libobjc.A.dylib 0x0000000194950790 0x194948000 + 34704
    1 CFNetwork 0x000000019897ff3c -[__NSCFURLSessionConnection dealloc] + 32 (SessionConnection.mm:357)
    2 CFNetwork 0x000000019897fc94 -[__NSCFURLLocalSessionConnection dealloc] + 260 (SessionConnection.mm:591)
    3 libsystem_blocks.dylib 0x0000000222264a20 <deduplicated_symbol> + 68
    4 libsystem_blocks.dylib 0x00000002222643e4 HelperBase::destroyBlock(Block_layout*, bool, unsigned char*) + 116 (runtime.cpp:471)
    5 libsystem_blocks.dylib 0x0000000222264868 _call_dispose_helpers_excp + 72 (generic_helpers.c:34)
    6 libsystem_blocks.dylib 0x0000000222264354 _Block_release + 236 (runtime.cpp:1017)
    7 libsystem_blocks.dylib 0x00000002222648e0 <deduplicated_symbol> + 68
    8 libsystem_blocks.dylib 0x0000000222264434 HelperBase::destroyBlock(Block_layout*, bool, unsigned char*) + 196 (runtime.cpp:479)
    9 libsystem_blocks.dylib 0x0000000222264868 _call_dispose_helpers_excp + 72 (generic_helpers.c:34)
    10 libsystem_blocks.dylib 0x0000000222264354 _Block_release + 236 (runtime.cpp:1017)
    11 libdispatch.dylib 0x000000019f357584 _dispatch_client_callout + 16 (client_callout.mm:85)
    12 libdispatch.dylib 0x000000019f3745a0 _dispatch_main_queue_drain.cold.5 + 812 (queue.c:8104)
    13 libdispatch.dylib 0x000000019f34cd30 _dispatch_main_queue_drain + 180 (queue.c:8085)
    14 libdispatch.dylib 0x000000019f34cc6c _dispatch_main_queue_callback_4CF + 44 (queue.c:8264)
    15 CoreFoundation 0x000000019742ded0 0x1973c1000 + 446160
    16 CoreFoundation 0x00000001973d1634 0x1973c1000 + 67124
    17 CoreFoundation 0x00000001973d2d7c 0x1973c1000 + 73084
    18 GraphicsServices 0x00000001e5025454 0x1e5024000 + 5204
    19 UIKitCore 0x0000000199ded890 0x199cb8000 + 1267856
    20 UIKitCore 0x0000000199db8cec 0x199cb8000 + 1051884

  8. rolfbjarne commented on Apr 22, 2025

    @rolfbjarne
    MemberAuthor

    No updates for the moment, there hasn't been any progress here.

  9. jonathanantoine commented on May 6, 2025

    @jonathanantoine

    I am seeing this a lot too. Any workaround maybe ?

  10. modified the milestones: Future, .NET 10 on May 6, 2025
  11. sleushunou commented on May 29, 2025

    @sleushunou

    I see more than 1000 crashes on my app last 90 days with this stacktrace:

    Thread 0 name: tid_103 Crashed:
    0 libobjc.A.dylib 0x305b34790 objc_release_x8
    1 CFNetwork 0x30db70f38 -[__NSCFURLSessionConnection dealloc]
    2 CFNetwork 0x30db70c90 -[__NSCFURLLocalSessionConnection dealloc]
    3 libsystem_blocks.dylib 0x41fe3da1c HelperBase::disposeCapture
    4 libsystem_blocks.dylib 0x41fe3d3e0 HelperBase::destroyBlock
    5 libsystem_blocks.dylib 0x41fe3d864 _call_dispose_helpers_excp
    6 libsystem_blocks.dylib 0x41fe3d350 _Block_release
    7 libsystem_blocks.dylib 0x41fe3d8dc HelperBase::disposeCapture
    8 libsystem_blocks.dylib 0x41fe3d430 HelperBase::destroyBlock
    9 libsystem_blocks.dylib 0x41fe3d864 _call_dispose_helpers_excp
    10 libsystem_blocks.dylib 0x41fe3d350 _Block_release
    11 libdispatch.dylib 0x31af55580 _dispatch_client_callout
    12 libdispatch.dylib 0x31af7259c _dispatch_main_queue_drain.cold.5
    13 libdispatch.dylib 0x31af4ad2c _dispatch_main_queue_drain
    14 libdispatch.dylib 0x31af4ac68 _dispatch_main_queue_callback_4CF
    15 CoreFoundation 0x30b092d8c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
    16 CoreFoundation 0x30b0364f0 __CFRunLoopRun
    17 CoreFoundation 0x30b037c38 CFRunLoopRunSpecific
    18 GraphicsServices 0x3a5405450 GSEventRunModal
    19 UIKitCore 0x310339270 -[UIApplication _run]
    20 UIKitCore 0x310304a24 UIApplicationMain
    21 Gambino.IOS 0x2014344ac xamarin_UIApplicationMain (bindings.m:126)
    22 Gambino.IOS 0x20178fd04 do_icall (interp.c:2310)
    23 Gambino.IOS 0x20178e37c do_icall_wrapper (interp.c:2350)
    24 Gambino.IOS 0x201782240 mono_interp_exec_method
    25 Gambino.IOS 0x20177fdac interp_runtime_invoke (interp.c:2109)
    26 Gambino.IOS 0x201745538 mono_jit_runtime_invoke (mini-runtime.c:3683)
    27 Gambino.IOS 0x2016e14e4 [inlined] do_runtime_invoke (object.c:2576)
    28 Gambino.IOS 0x2016e14e4 mono_runtime_invoke_checked (object.c:2792)
    29 Gambino.IOS 0x2016e8608 [inlined] do_exec_main_checked
    30 Gambino.IOS 0x2016e8608 mono_runtime_exec_main_checked (object.c:4775)
    31 Gambino.IOS 0x20174ce84 [inlined] mono_jit_exec_internal (driver.c:1369)
    32 Gambino.IOS 0x20174ce84 mono_jit_exec (driver.c:1314)
    33 Gambino.IOS 0x2014486f0 xamarin_main (monotouch-main.m:495)
    34 Gambino.IOS 0x2017b54d8 main (main.arm64.mm:84)
    35 0x1af387f08

  12. Zalkovalsky commented on Jul 10, 2025

    @Zalkovalsky

    I have seen this issue on the latest .NET 9 sdk (9.0.302) too, although it's quite random in timing

  13. sleushunou commented on Oct 13, 2025

    @sleushunou

    @rolfbjarne this bug fill be fixed in Net10?

  14. 13 remaining items

  15. rolfbjarne commented on Sep 21, 2026

    @rolfbjarne
    MemberAuthor

    @jonathanantoine that's unfortunate 😒 but yes, please share the full thread dump.

  16. added
    need-attention
    on Sep 21, 2026
  17. mlancione commented on Sep 21, 2026

    @mlancione

    @rolfbjarne @jonathanantoine An update to the workaround I shared in April: following investigation of app crash logs, we removed explicit NSUrlSessionTask.Dispose() calls from both RemoveInflightData and handler Dispose in our local implementation.

    The per-request cleanup change may be relevant to the static, never-disposed HttpClient case. The current upstream implementation still calls task?.Dispose() unconditionally in RemoveInflightData, including when cancel is false:

    DidCompleteWithError
      → RemoveInflightData(task, cancel: false)
      → task.Dispose()
    
    Response-content disposal
      → RemoveInflightData(dataTask)
      → task.Cancel()
      → task.Dispose()
    

    Keeping the handler alive therefore does not prevent individual task wrappers from being explicitly disposed. #25183 retains this behavior.

    Our relevant change was:

     if (cancel)
         task?.Cancel();
    
    -task?.Dispose();
    

    We also removed task.Dispose() from the handler’s disposal loop, retaining cancellation and session.InvalidateAndCancel().
    Our concern was releasing the wrapper’s native reference while callbacks or other cleanup paths could still involve that task. This changes release timing, but we have not established that it fixes the __NSCFURLSessionConnection dealloc crash.

    For the latest report, removing explicit task disposal from per-request cleanup seems worth testing independently, under the same concurrent HTTPS workload, while monitoring crash frequency and native memory usage.

  18. filipnavara commented on Sep 21, 2026

    @filipnavara
    Member

    We are likely hitting the same issue too, but the NativeAOT stack trace is a bit spares:

    SIGSEGV: cancel >
    Attempted to dereference garbage pointer at 0x77934d630728c0.
      libobjcMsgSend      0x1921b0820  null
      MailClient.Mobile.iOS0x1018d343c  null
      MailClient.Mobile.iOS0x1018b8904  _Microsoft_iOS_System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate___c__DisplayClass5_0___DidReceiveResponseImpl_b__0 (NSUrlSessionHandler.cs:848)
      MailClient.Mobile.iOS0x1018b9578  _Microsoft_iOS_System_Net_Http_NSUrlSessionHandler_NSUrlSessionDataTaskStreamContent__Dispose (NSUrlSessionHandler.cs:1229)
      MailClient.Mobile.iOS0x101b2d67c  _System_Net_Http_System_Net_Http_HttpResponseMessage__Dispose (HttpResponseMessage.cs:217)
      MailClient.Mobile.iOS0x1014f9558  _Microsoft_Exchange_WebServices_Data_Microsoft_Exchange_WebServices_Data_HangingServiceRequestBase__Disconnect_0 (HangingServiceRequestBase.cs:324)
      MailClient.Mobile.iOS0x101c784f4  _S_P_CoreLib_System_Threading_ExecutionContext__RunFromThreadPoolDispatchLoop (ExecutionContext.cs:264)
      MailClient.Mobile.iOS0x101c80db8  _S_P_CoreLib_System_Threading_TimerQueueTimer__Fire (Timer.cs:686)
      MailClient.Mobile.iOS0x101c7f108  _S_P_CoreLib_System_Threading_ThreadPoolWorkQueue__DispatchItemWithAutoreleasePool (ThreadPoolWorkQueue.AutoreleasePool.OSX.cs:24)
      MailClient.Mobile.iOS0x101c7eeb8  _S_P_CoreLib_System_Threading_ThreadPoolWorkQueue__Dispatch (ThreadPoolWorkQueue.cs:1040)
      MailClient.Mobile.iOS0x101d2200c  _S_P_CoreLib_System_Threading_PortableThreadPool_WorkerThread__WorkerThreadStart (PortableThreadPool.WorkerThread.cs:118)
      MailClient.Mobile.iOS0x101c74dd4  _S_P_CoreLib_System_Threading_Thread__StartThread (Thread.NativeAot.cs:459)
      MailClient.Mobile.iOS0x101c75420  _S_P_CoreLib_System_Threading_Thread__ThreadEntryPoint (Thread.NativeAot.Unix.cs:121)
      libsystem_pthread   0x18a6ee038  null
    

    I am analyzing the Sentry data to see if there are any more clues. We didn't manage to produce a successful repro yet.

  19. filipnavara commented on Sep 21, 2026

    @filipnavara
    Member

    I think I have a repro:

    =================================================================
            Native stacktrace:
    =================================================================
            0x1028f6f40 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/libmonosgen-2.0.dylib : mono_dump_native_crash_info
            0x1028a6cd4 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/libmonosgen-2.0.dylib : mono_handle_native_crash
            0x1028190c8 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/libmonosgen-2.0.dylib : mono_sigsegv_signal_handler_debug
            0x101f3ffe0 - /usr/lib/system/libsystem_platform.dylib : _sigtramp
            0x1024e7334 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/libxamarin-dotnet-debug.dylib : xamarin_dyn_objc_msgSend
            0x101860628 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : wrapper_managed_to_native_ObjCRuntime_Messaging_void_objc_msgSend_intptr_intptr
            0x101819ee0 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : Foundation_NSUrlSessionTask_Cancel
            0x101823ce4 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Net_Http_NSUrlSessionHandler_NSUrlSessionHandlerDelegate__c__DisplayClass5_0__DidReceiveResponseImplb__0
            0x1018244b4 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Net_Http_NSUrlSessionHandler_NSUrlSessionDataTaskStreamContent_Dispose_bool
            0x1018c039c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Net_Http_HttpContent_Dispose
            0x1018c5224 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Net_Http_HttpResponseMessage_Dispose_bool
            0x1018c527c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Net_Http_HttpResponseMessage_Dispose
            0x1013847e4 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : NSUrlSessionHandlerRace_RaceHarness__RunOneAsyncd__26_MoveNext
            0x1016be550 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_AsyncStateMachineBox_1_TResult_GSHAREDVT_TStateMachine_GSHAREDVT_ExecutionContextCallback_object
            0x1014ebd0c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_ExecutionContext_RunInternal_System_Threading_ExecutionContext_System_Threading_ContextCallback_object
            0x1016bf03c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_AsyncStateMachineBox_1_TResult_GSHAREDVT_TStateMachine_GSHAREDVT_MoveNext_System_Threading_Thread
            0x10173751c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : gsharedvt_trampoline
            0x101737b9c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : gsharedvt_out_trampoline
            0x1016bee84 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_AsyncStateMachineBox_1_TResult_GSHAREDVT_TStateMachine_GSHAREDVT_MoveNext
            0x101518428 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_AwaitTaskContinuation_RunOrScheduleAction_System_Runtime_CompilerServices_IAsyncStateMachineBox_bool
            0x10151171c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_RunContinuations_object
            0x101511524 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_FinishContinuations
            0x10150aed4 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_1_TResult_REF_TrySetResult_TResult_REF
            0x101519958 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_TaskFactory_CompleteOnInvokePromise_1_TTask_REF_Invoke_System_Threading_Tasks_Task
            0x101511f04 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_RunOrQueueCompletionAction_System_Threading_Tasks_ITaskCompletionAction_bool
            0x101511804 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_RunContinuations_object
            0x101511524 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_FinishContinuations
            0x1016f30b8 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_1_System_Threading_Tasks_VoidTaskResult_TrySetResult_System_Threading_Tasks_VoidTaskResult
            0x1016f3e78 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_System_Threading_Tasks_VoidTaskResult_SetExistingTaskResult_System_Threading_Tasks_Task_1_System_Threading_Tasks_VoidTaskResult_System_Threading_Tasks_VoidTaskResult
            0x10153e79c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_SetResult
            0x1013823f4 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : NSUrlSessionHandlerRace_RaceHarness__CancelSoonAsyncd__29_MoveNext
            0x101394808 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_AsyncStateMachineBox_1_System_Threading_Tasks_VoidTaskResult_NSUrlSessionHandlerRace_RaceHarness__CancelSoonAsyncd__29_ExecutionContextCallback_object
            0x1014ebd0c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_ExecutionContext_RunInternal_System_Threading_ExecutionContext_System_Threading_ContextCallback_object
            0x1013957c8 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_AsyncStateMachineBox_1_System_Threading_Tasks_VoidTaskResult_NSUrlSessionHandlerRace_RaceHarness__CancelSoonAsyncd__29_MoveNext_System_Threading_Thread
            0x101395598 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_AsyncStateMachineBox_1_System_Threading_Tasks_VoidTaskResult_NSUrlSessionHandlerRace_RaceHarness__CancelSoonAsyncd__29_MoveNext
            0x101518428 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_AwaitTaskContinuation_RunOrScheduleAction_System_Runtime_CompilerServices_IAsyncStateMachineBox_bool
            0x10151171c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_RunContinuations_object
            0x101511524 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_FinishContinuations
            0x1015112f8 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_TrySetResult
            0x101515170 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_DelayPromise_CompleteTimedOut
            0x101515128 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Tasks_Task_DelayPromise_TimerCallback_object
            0x1014ff764 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_TimerQueueTimer_CallCallback_bool
            0x1014ff4b8 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_TimerQueueTimer_Fire_bool
            0x1014ff320 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_TimerQueueTimer_System_Threading_IThreadPoolWorkItem_Execute
            0x1014f8c94 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_ThreadPoolWorkQueue_DispatchWorkItem_object_System_Threading_Thread
            0x1014f8e2c - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_ThreadPoolWorkQueue_DispatchItemWithAutoreleasePool_object_System_Threading_Thread
            0x1014f89a0 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_ThreadPoolWorkQueue_Dispatch
            0x101505e34 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_PortableThreadPool_WorkerThread_WorkerThreadStart
            0x1014e2ad4 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Thread_StartHelper_RunWorker
            0x1014e0f20 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : System_Threading_Thread_StartCallback
            0x1016f6dd8 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/NSUrlSessionHandlerRace : wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr
            0x10281c228 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/libmonosgen-2.0.dylib : mono_jit_runtime_invoke
            0x1029bde24 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlS2026-09-21 14:50:32.167548+0200 NSUrlSessionHandlerRace[84449:15780457] [connection] nw_socket_output_finished [C653:2] shutdown(235, SHUT_WR) [57: Socket is not connected]
    essionHandlerRace.app/libmonosgen-2.0.dylib : mono_runtime_invoke_checked
            0x1029d4570 - /Users/navara/Library/Developer/CoreSimulator/Devices/A1FAB8EC-910C-480C-BA12-9DB447837382/data/Containers/Bundle/Application/F369A77E-28F3-4B1D-921A-D4F12286299D/NSUrlSessionHandlerRace.app/libmonosgen-2.0.dylib : start_wrapper
            0x1025ba680 - /usr/lib/system/libsystem_pthread.dylib : _pthread_start
            0x1025b5a88 - /usr/lib/system/libsystem_pthread.dylib : thread_start
    

    NSUrlSessionHandlerRace.zip

  20. filipnavara commented on Sep 21, 2026

    @filipnavara
    Member

    I was lucky with the first crash happening in few seconds, it seems, but the underlying cause seems to be parallel calls to RemoveInflightData. Only the first one succeeds in removing the request from inflightRequests under the lock. However, both will try to cancel/dispose the task. There doesn't seem to be proper protection for the Dispose being called from multiple threads at the same time. This could result in second attempt to release the native object.

    if (cancel)
    task?.Cancel ();
    task?.Dispose ();

    Presumably this may fix it:

    --- a/src/Foundation/NSUrlSessionHandler.cs
    +++ b/src/Foundation/NSUrlSessionHandler.cs
    @@ -184,17 +184,22 @@ namespace Foundation {
     
                    void RemoveInflightData (NSUrlSessionTask task, bool cancel = true)
                    {
    +                       bool removed;
    +
                            lock (inflightRequestsLock) {
    -                               if (inflightRequests.Remove (task, out var data)) {
    +                               removed = inflightRequests.Remove (task, out var data);
    +                               if (removed) {
                                            if (cancel)
                                                    data.CancellationTokenSource.Cancel ();
                                    }
                            }
     
    -                       if (cancel)
    -                               task?.Cancel ();
    +                       if (removed) {
    +                               if (cancel)
    +                                       task?.Cancel ();
     
    -                       task?.Dispose ();
    +                               task?.Dispose ();
    +                       }
                    }
     
                    /// <inheritdoc />
  21. rolfbjarne commented on Sep 21, 2026

    @rolfbjarne
    MemberAuthor

    I think I have a repro:

    [...]

    NSUrlSessionHandlerRace.zip

    Thanks for the test case! A fix is in progress (looks somewhat similar to what you suggested).

  22. removed
    need-attention
    on Sep 21, 2026
  23. modified the milestones: .NET 10, Future on Sep 21, 2026
  24. added a commit that references this issue on Sep 24, 2026
    d773862
  25. added a commit that references this issue on Sep 26, 2026
    bc0738d
  26. jonathanantoine commented on Oct 8, 2026

    @jonathanantoine

    @rolfbjarne @filipnavara thanks a lot for the repro and the fix. That race explains every variant I see (main queue and NSURLSession-work queue, zero managed frames).

    Is a backport of #26668 to .NET 10 servicing planned? I only see the release/11.0.1xx-rc.2 one (#26730). My app ships on net10.0-ios (Microsoft.iOS 26.5.x) and still gets this crash in production on every build, about 3-4 a day over the last two weeks, from static, never-disposed HttpClient instances. Moving to .NET 11 is not something I can do right away, so a 10.0 servicing fix would help a lot.

  27. rolfbjarne commented on Oct 14, 2026

    @rolfbjarne
    MemberAuthor

    @jonathanantoine

     Is a backport of [#26668](https://github.com/dotnet/macios/pull/26668) to .NET 10 servicing planned? I only see the release/11.0.1xx-rc.2 one ([#26730](https://github.com/dotnet/macios/pull/26730)). My app ships on net10.0-ios (Microsoft.iOS 26.5.x) and still gets this crash in production on every build, about 3-4 a day over the last two weeks, from static, never-disposed HttpClient instances. Moving to .NET 11 is not something I can do right away, so a 10.0 servicing fix would help a lot.
    

    I've started the backporting process to .NET 10, but I'm not sure when it'll actually be released. The changes are somewhat risky, so we might wait a bit to see if anybody reports any regressions in .NET 11 before we backport to .NET 10.

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

    bugnetworking

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions