Fix crash in Messaging on Android when Terminate is called while tasks are still pending. by TBarendt · Pull Request #739 · firebase/firebase-cpp-sdk

@TBarendt

When firebase::messaging::Terminate is called while there are still pending tasks left a null pointer exception is causing an ANR on Andriod.

FutureData is destroyed before calling util::Terminate which in turn will try to cancel all pending callbacks. This will call cancel() in JniResultCallback.java which will lock a mutex and callback into C++ using the JniResultCallback_nativeResult function. Depending on the task canceled it will call into different callbacks in messaging.cc and some of them as for example CompleteStringCallback are using FutureData which has already been destroyed. This will cause the thread to stop and the mutex in JniResultCallbak.java to remain locked. The next message that either completes or fails will now end up in a dead lock causing an ANR.

The proposed fix is to not destroy FutureData until after the tasks have been canceled.

@jonsimantov jonsimantov changed the title Andriod ANR Fix crash in Messaging on Android when Terminate is called while tasks are still pending.

Nov 5, 2021

@TBarendt

@TBarendt

jonsimantov

@firebase firebase locked and limited conversation to collaborators

Dec 9, 2021