Skip to content

Commit e4d43e5

Browse files
authored
Fix crash in Messaging on Android when Terminate is called while tasks are still pending. (#739)
* 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. * Updated readme
1 parent b7ca2e2 commit e4d43e5

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

messaging/src/android/cpp/messaging.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ void Terminate() {
704704
g_firebase_messaging = nullptr;
705705
SetListener(nullptr);
706706
ReleaseClasses(env);
707-
FutureData::Destroy();
708707
util::Terminate(env);
708+
FutureData::Destroy();
709709
}
710710

711711
// Start a service which will communicate with the Firebase Cloud Messaging

release_build_files/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ code.
572572
- Auth (Desktop): Fixed a crash in `error_code()` when a request
573573
is cancelled or times out.
574574
([#737](https://github.com/firebase/firebase-cpp-sdk/issues/737))
575+
- Messaging (Android): Fixed crash during termination.
576+
([#739](https://github.com/firebase/firebase-cpp-sdk/pull/739))
575577

576578
### 8.7.0
577579
- Changes

0 commit comments

Comments
 (0)