From 366965cb79ef7d51cc55d77cf1fde457687f629c Mon Sep 17 00:00:00 2001 From: Tobias Barendt Date: Fri, 5 Nov 2021 21:20:08 +0000 Subject: [PATCH 1/2] Andriod ANR 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. --- messaging/src/android/cpp/messaging.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging/src/android/cpp/messaging.cc b/messaging/src/android/cpp/messaging.cc index dff7aacea6..8f5d257bec 100644 --- a/messaging/src/android/cpp/messaging.cc +++ b/messaging/src/android/cpp/messaging.cc @@ -704,8 +704,8 @@ void Terminate() { g_firebase_messaging = nullptr; SetListener(nullptr); ReleaseClasses(env); - FutureData::Destroy(); util::Terminate(env); + FutureData::Destroy(); } // Start a service which will communicate with the Firebase Cloud Messaging From c14147ae8a270a41c23dc86eb89bddd40ff40e66 Mon Sep 17 00:00:00 2001 From: Tobias Barendt Date: Fri, 5 Nov 2021 23:04:06 +0000 Subject: [PATCH 2/2] Updated readme --- release_build_files/readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release_build_files/readme.md b/release_build_files/readme.md index 09cddbb702..739dc91794 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -572,6 +572,8 @@ code. - Auth (Desktop): Fixed a crash in `error_code()` when a request is cancelled or times out. ([#737](https://github.com/firebase/firebase-cpp-sdk/issues/737)) + - Messaging (Android): Fixed crash during termination. + ([#739](https://github.com/firebase/firebase-cpp-sdk/pull/739)) ### 8.7.0 - Changes