couchdeveloper / RXPromise

An Objective-C Class which implements the Promises/A+ specification.
Other
276 stars 29 forks source link

Crash in dealloc #33

Open dispatchqueue opened 8 years ago

dispatchqueue commented 8 years ago

I receive this crash report:

EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 0x000000016e24ffb0

Thread : Crashed: RXPromise.shared_sync_queue 0 libsystem_malloc.dylib 0x19a6c9f4c tiny_free_list_remove_ptr + 86 1 libsystem_malloc.dylib 0x19a6c8adc szone_free_definite_size + 1128 2 libdispatch.dylib 0x19a552028 _dispatch_queue_dispose + 28 3 libdispatch.dylib 0x19a551bbc _dispatch_dispose + 56 4 libdispatch.dylib 0x19a54d804 -[OS_dispatch_object _xref_dispose] + 56 5 Directory 0x10026255c -RXPromise .cxx_destruct 6 libobjc.A.dylib 0x199d3ab54 object_cxxDestructFromClass(objcobject, objcclass) + 148 7 libobjc.A.dylib 0x199d46080 objc_destructInstance + 92 8 libobjc.A.dylib 0x199d460e0 object_dispose + 28 9 Directory 0x10025ecc8 -RXPromise dealloc 10 libobjc.A.dylib 0x199d3ab54 object_cxxDestructFromClass(objcobject, objcclass) + 148 11 libobjc.A.dylib 0x199d46080 objc_destructInstance + 92 12 libobjc.A.dylib 0x199d460e0 object_dispose + 28 ... 501 Directory 0x10025ecc8 -RXPromise dealloc 502 libobjc.A.dylib 0x199d3ab54 object_cxxDestructFromClass(objcobject, objcclass) + 148 503 libobjc.A.dylib 0x199d46080 objc_destructInstance + 92 504 libobjc.A.dylib 0x199d460e0 object_dispose + 28 505 Directory 0x10025ecc8 -RXPromise dealloc 506 libobjc.A.dylib 0x199d3ab54 object_cxxDestructFromClass(objcobject, objcclass) + 148 507 libobjc.A.dylib 0x199d46080 objc_destructInstance + 92 508 libobjc.A.dylib 0x199d460e0 object_dispose + 28 509 Directory 0x10025ecc8 -RXPromise dealloc 510 libobjc.A.dylib 0x199d3ab54 object_cxxDestructFromClass(objcobject, objcclass) + 148 511 libobjc.A.dylib 0x199d46080 objc_destructInstance + 92

promise

This crash report is get from Xcode and Crashlytics. Look like a stack overflow exception. I don't know how to reproduce it. Do you have any ideas why it happens? Thank you!

couchdeveloper commented 8 years ago

Could you please provide your code where this happens? Do you possibly use anywhere a global variable as an RXPromise?

dispatchqueue commented 8 years ago

Thanks for your reply. I use promise alot in my app. I don't see my code in the crash report, both Xcode and Crashlytics. All I see is -[RXPromise dealloc]. Can you explain me why global promise could cause this crash?

couchdeveloper commented 8 years ago

Well, it should not. I've never seen a crash so far. However, I vaguely remember that there was an issue with global promises. So, we need more info:

It seems, there is a chain of roughly one hundred promises which get released - executing on the shared synchronisation queue (Shared.sync_queue whose label equals "RXPromise.shared_sync_queue").

It also seems, the last promise which is being deallocated, deallocates a dispatch queue. When a queue will be deallocated it has no active or enqueued blocks. This might be the "_handler_queue" of this promise which would mean, that the handler queue has been created through registering a handler, and then the promise has been subsequently cancelled since it has currently no handlers anymore.

Might this be correct?

couchdeveloper commented 8 years ago

I've tried to reproduce this error - but cannot force it to fail like yours. What I can say about it, is that it's happening quite late during disposing off the handler queue while RXPromise is being deallocated. All the crucial stuff of disposing a dispatch queue has already been passed successfully, but it failed while freeing internally allocated memory. This could be a corrupt heap - caused by other, unrelated code.

In order to verify this, I would suggest you create a debug build with a Scheme where you enabled memory related flags, like "Enable Guard Alloc", etc. Then try to reproduce the error on a device. This may hopefully reveal more details.

dispatchqueue commented 8 years ago

Thank you, Andreas! I also tried to reproduce this error but cannot create a long stacktrace like that. It does look like a stack overflow crash. I will try to test the app with the settings you suggest.