You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift Concurrency中‘suspend resume partial function’崩溃问题排查

Swift Concurrency崩溃问题解析:"suspend resume partial function"含义与成因

我们收到了包含suspend resume partial function字样的崩溃报告,问题源于Swift Concurrency的使用。以下是堆栈追踪示例:

Crashed: com.apple.root.user-initiated-qos.cooperative
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000cf855c2e0
0  libobjc.A.dylib                0x4174 objc_release + 16
1  libobjc.A.dylib                0x4174 objc_release_x0 + 16
2  libswiftCore.dylib             0x3ad2c8 swift_arrayDestroy + 124
3  libswiftCore.dylib             0x98f38 _ContiguousArrayStorage.__deallocating_deinit + 96
4  libswiftCore.dylib             0x3bd628 _swift_release_dealloc + 56
5  libswiftCore.dylib             0x3be44c bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 132
6  MyAppName                      0x32e08c (3) suspend resume partial function for ProductUpdater.updateProducts() + 138 (Products.swift:138)
7  libswift_Concurrency.dylib     0x41948 swift::runJobInEstablishedExecutorContext(swift::Job*) + 416
8  libswift_Concurrency.dylib     0x42868 swift_job_runImpl(swift::Job*, swift::ExecutorRef) + 72
9  libdispatch.dylib              0x15944 _dispatch_root_queue_drain + 396
10 libdispatch.dylib              0x16158 _dispatch_worker_thread2 + 164
11 libsystem_pthread.dylib        0xda0 _pthread_wqthread + 228
12 libsystem_pthread.dylib        0xb7c start_wqthread + 8

Crashlytics将调用栈第6行标记为问题根源:(3) suspend resume partial function for ProductUpdater.updateProducts()。

核心疑问

请问suspend resume partial function具体是什么意思?它指向程序执行了什么操作导致崩溃?

相关代码框架

struct Product: Codable, Equatable {
    var id: String
    var name: String
    var price: Int
}

struct ProductWrapper: Codable, Equatable {
    var metadata: String
    var products: [Product]

    static let none = ProductWrapper(metadata: "none", products: [])
}

class ProductUpdater {
    var userIsSignedIn: Bool = false
    var products: ProductWrapper = .none

    init() {
        Task {
            await updateProducts()
        }
    }

    private func updateProducts() async {
        // 如果用户未登录,则无法获取产品
        guard userIsSignedIn else {
            products = .none
            return
        }

        do {
            // 以下是原代码的第138行:
            products = try await NetworkService.fetchProducts()
        } catch {
            print("无法获取产品: \(error)")
        }
    }
}

尝试过的无效方案

根据GitHub某个issue的模糊建议,我尝试将products的赋值包裹在无意义的continuation中,但问题并未解决:

private func updateProducts() async {
    // 如果用户未登录,则无法获取产品
    guard userIsSignedIn else {
        products = .none
        return
    }

    do {
        let updatedProducts = try await NetworkService.fetchProducts()
        await withCheckedContinuation { continuation in
            products = updatedProducts
            continuation.resume()
        }
    } catch {
        print("无法获取产品: \(error)")
    }
}

我们使用Xcode Cloud构建版本,当前环境为Xcode 14.3.1(Swift 5.8.1)。


内容的提问来源于stack exchange,提问作者bdesham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 10:37:33