alibaba / coobjc

coobjc provides coroutine support for Objective-C and Swift. We added await method、generator and actor model like C#、Javascript and Kotlin. For convenience, we added coroutine categories for some Foundation and UIKit API in cokit framework like NSFileManager, JSON, NSData, UIImage etc. We also add tuple support in coobjc.
https://github.com/alibaba/coobjc
Apache License 2.0
4.03k stars 525 forks source link

调用函数 void coroutine_resume_im(coroutine_t *co) 时,没有保证 coroutine_t 的状态为 Ready 或 Suspend #84

Open jieliangma opened 5 years ago

jieliangma commented 5 years ago

堆栈 image

推测崩溃的代码行:coroutine.m:237

NianJi commented 5 years ago

协程的block是有重入吗?理论上正常使用不应该进入这里

jeffdgr8 commented 4 years ago

I am getting these same crashes in crash logs from the app I recently added coswift to.

Crashed: com.apple.root.default-qos
SIGABRT ABORT 0x0000000183a0fd88
Crashed: com.apple.root.default-qos
0  libsystem_kernel.dylib         0x183a0fd88 __pthread_kill + 8
1  libsystem_pthread.dylib        0x1839281e8 pthread_kill$VARIANT$mp + 136
2  libsystem_c.dylib              0x18387b934 abort + 100
3  libsystem_c.dylib              0x18387ad54 err + 286
4  cocore                         0x103d749b4 coroutine_resume_im + 348
5  cocore                         0x103d74790 coroutine_scheduler_main + 76
6  cocore                         0x103d74ae8 coroutine_main + 32

The crash is on the assert at the bottom of the function, indicating the coroutine status is neither ready nor suspended.

My usage is fairly straightforward, launching a single coroutine with several async functions using a channel to suspend the coroutine while performing some database I/O.

I will swap the channels out to use promises instead and note if the crashes continue afterwards.

jeffdgr8 commented 4 years ago

After changing the Chans to Promises, the crash continues. So this isn't specifically caused by one or the other.

NianJi commented 4 years ago

Could you provide the demo code?

jeffdgr8 commented 4 years ago

This seems to be resolved with a change I made to ensure canceling an active coroutine before dismissing a view controller.