Skip to content

Commit 94ae2ac

Browse files
authored
Fix deadlock when handling simultaneous messages. (#4327)
#4315 * Released sendWakefulServiceIntent()'s WakeLock on the main thread instead of within WithinAppServiceConnection to prevent a deadlock trying to acquire the WakeLockHolder.syncObject.
1 parent 42e5b8a commit 94ae2ac

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

firebase-messaging/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Unreleased
22

3+
# 23.1.1
4+
5+
* [fixed] Fixed deadlock when handling simultaneous messages.
6+
37
# 23.1.0
48
* [unchanged] Updated to accommodate the release of the updated
59
[messaging_longer] Kotlin extensions library.
610

7-
811
## Kotlin
912
The Kotlin extensions library transitively includes the updated
1013
`firebase-messaging` library. The Kotlin extensions library has the following

firebase-messaging/src/main/java/com/google/firebase/messaging/WakeLockHolder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ static void sendWakefulServiceIntent(
108108
wakeLock.acquire(WAKE_LOCK_ACQUIRE_TIMEOUT_MILLIS);
109109
}
110110

111-
connection
112-
.sendIntent(intent)
113-
.addOnCompleteListener(Runnable::run, t -> completeWakefulIntent(intent));
111+
connection.sendIntent(intent).addOnCompleteListener(t -> completeWakefulIntent(intent));
114112
}
115113
}
116114

firebase-messaging/src/test/java/com/google/firebase/messaging/WakeLockHolderRoboTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.Test;
2828
import org.junit.runner.RunWith;
2929
import org.robolectric.RobolectricTestRunner;
30+
import org.robolectric.shadows.ShadowLooper;
3031
import org.robolectric.shadows.ShadowPowerManager;
3132

3233
@RunWith(RobolectricTestRunner.class)
@@ -77,6 +78,7 @@ public void testSendWakefulServiceIntent_ReleasesWakeLock() {
7778
WakeLock wakeLock = ShadowPowerManager.getLatestWakeLock();
7879
taskCompletionSource.setResult(null);
7980

81+
ShadowLooper.idleMainLooper();
8082
assertThat(wakeLock.isHeld()).isFalse();
8183
}
8284

0 commit comments

Comments
 (0)