Skip to content

withDiscardingTaskGroup cancelAll crash #80808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KeithBauerANZ opened this issue Apr 14, 2025 · 1 comment
Closed

withDiscardingTaskGroup cancelAll crash #80808

KeithBauerANZ opened this issue Apr 14, 2025 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@KeithBauerANZ
Copy link

Description

Occasionally, calling cancelAll on a DiscardingTaskGroup will crash.

Reproduction

var i = 0
while true {
    print("\(i)")
    await withDiscardingTaskGroup { group in
        group.addTask {
            _ = try? await Task.sleep(nanoseconds: .max / 2)
        }

        group.cancelAll()
    }
    i += 1
}
swiftc -swift-version 6 TaskGroupCancelAllCrash.swift && lldb ./TaskGroupCancelAllCrash
r
...
1830090
Process 87524 stopped
* thread #4, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x00000002654ded1c libswift_Concurrency.dylib`withStatusRecordLock(swift::AsyncTask*, swift::ActiveTaskStatus, __swift::__runtime::llvm::function_ref<void (swift::ActiveTaskStatus)>, __swift::__runtime::llvm::function_ref<void (swift::ActiveTaskStatus, swift::ActiveTaskStatus&)>) + 396
libswift_Concurrency.dylib`withStatusRecordLock:
->  0x2654ded1c <+396>: ldr    x9, [x27, #0x8]
    0x2654ded20 <+400>: orr    x8, x8, x28, lsl #32
    0x2654ded24 <+404>: stp    x8, x9, [sp, #0x20]
    0x2654ded28 <+408>: cbz    x21, 0x2654ded40 ; <+432>
Target 0: (TaskGroupCancelAllCrash) stopped.

Stack dump

(lldb) bt all
  thread #2
    frame #0: 0x0000000184bc0ba4 libsystem_kernel.dylib`__workq_kernreturn + 8
  thread #3
    frame #0: 0x0000000184bc6684 libsystem_kernel.dylib`__sigsuspend_nocancel + 8
    frame #1: 0x0000000184a60c64 libdispatch.dylib`_dispatch_sigsuspend + 48
    frame #2: 0x0000000184a60c34 libdispatch.dylib`_dispatch_sig_thread + 60
* thread #4, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
  * frame #0: 0x00000002654ded1c libswift_Concurrency.dylib`withStatusRecordLock(swift::AsyncTask*, swift::ActiveTaskStatus, __swift::__runtime::llvm::function_ref<void (swift::ActiveTaskStatus)>, __swift::__runtime::llvm::function_ref<void (swift::ActiveTaskStatus, swift::ActiveTaskStatus&)>) + 396
    frame #1: 0x00000002654df7b8 libswift_Concurrency.dylib`swift_task_cancelImpl(swift::AsyncTask*) + 216
    frame #2: 0x00000002654e12d8 libswift_Concurrency.dylib`swift_taskGroup_cancelAll + 144
    frame #3: 0x0000000100001270 TaskGroupCancelAllCrash`(1) suspend resume partial function for closure #1 (inout Swift.DiscardingTaskGroup) async -> () in TaskGroupCancelAllCrash + 112
    frame #4: 0x00000002654a50d0 libswift_Concurrency.dylib`(2) await resume partial function for Swift.withDiscardingTaskGroup<τ_0_0>(returning: τ_0_0.Type, isolation: isolated Swift.Optional<Swift.Actor>, body: (inout Swift.DiscardingTaskGroup) async -> τ_0_0) async -> τ_0_0
    frame #5: 0x0000000100000b60 TaskGroupCancelAllCrash`async_MainTQ0_
    frame #6: 0x0000000100000f30 TaskGroupCancelAllCrash`(1) await resume partial function for reabstraction thunk helper from @escaping @convention(thin) @async () -> () to @escaping @callee_guaranteed @async () -> (@out (), @error @owned Swift.Error)
    frame #7: 0x0000000100001058 TaskGroupCancelAllCrash`(1) await resume partial function for partial apply forwarder for reabstraction thunk helper from @escaping @convention(thin) @async () -> () to @escaping @callee_guaranteed @async () -> (@out (), @error @owned Swift.Error)
  thread #5
    frame #0: 0x0000000184bc0ba4 libsystem_kernel.dylib`__workq_kernreturn + 8
  thread #6
    frame #0: 0x0000000184bc0ba4 libsystem_kernel.dylib`__workq_kernreturn + 8

Expected behavior

Not… crash

Environment

 swiftc -version
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

Additional information

No response

@KeithBauerANZ KeithBauerANZ added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Apr 14, 2025
@mikeash
Copy link
Contributor

mikeash commented Apr 21, 2025

This should be fixed by #80096.

@mikeash mikeash closed this as completed Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants