ReactiveX / RxSwift

Reactive Programming in Swift
MIT License
24.38k stars 4.17k forks source link

EXC_BAD_ACCESS Crash with Timer #2259

Closed 623637646 closed 3 years ago

623637646 commented 3 years ago

Short description of the issue:

EXC_BAD_ACCESS Crash

Screenshot 2020-11-14 at 7 25 02 PM

Expected outcome:

No crash

What actually happens:

Crash

Self contained code example that reproduces the issue:

        let obj = Timer.init()
        _ = obj.rx.sentMessage(#selector(Timer.description)).subscribe(onNext: { (a) in
            print("")
        }, onError: { (error) in
            print("")
        }, onCompleted: {
            print("")
        }, onDisposed: {
            print("")
        })

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

RxCocoa (5.1.1) RxRelay (5.1.1) RxSwift (5.1.1)

Platform/Environment

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

Xcode version:

  Xcode 11.5

:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:

Installation method:

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

ghost commented 3 years ago

@623637646 From what I can see it seems that issue lies within Timer itself. If you create timer with one of the convenience initialisers it works (do not crash). I believe that internals of timer are not correctly initialised (eg. isValid returns false).

Also keep in mind that: "Interception of messages sent to Core Foundation isn't supported".

623637646 commented 3 years ago

I see. Thank you so much. @TLizer .
Do you have any more references about Interception of messages sent to Core Foundation isn't supported?

ghost commented 3 years ago

Do you have any more references about Interception of messages sent to Core Foundation isn't supported?

Timer.description is part of Timer and it is defined inside Foundation framework and this means that you cannot intercept messages sent to such objects. You can find more info in the associated error description: https://github.com/ReactiveX/RxSwift/blob/6ccd6719af8a86bf18c2239e231c0276fd861068/RxCocoa/Common/RxCocoaObjCRuntimeError%2BExtensions.swift To make it short rx.sentMessage won't work on Foundation objects directly.

Could you maybe describe what where you trying to achieve with this code snippet you posted?

oteronavarretericardo commented 3 years ago

Interesting that the validation that would throw .cantInterceptCoreFoundationTollFreeBridgedObjects is not hit

623637646 commented 3 years ago

Could you maybe describe what where you trying to achieve with this code snippet you posted?

Hi, @TLizer This code is only for testing. I will not use it on live because Timer.init() is not a formal way to init Timer. My concern is that RxSwift should throw Error instead of crash (If we can do this).

About this conclusion Interception of messages sent to Core Foundation isn't supported. Does Apple or other official documents say this? How do you know we can't intercept the object's method of Core Foundation?

freak4pc commented 3 years ago

Indeed the problem stems mainly from the fact that you are using Timer.init which should not be used. Message interception doesn't always work, and I personally prefer crashing in these unexpected cases. Throwing makes sense for a "I can continue working" sort of runtime error, but crashing for something entirely unexpected.