firebase-android-sdk
firebase-android-sdk copied to clipboard
Firebase Storage - StorageTask cannot be canceled while the network connection is unavailable
[REQUIRED] Step 2: Describe your environment
- Android Studio version: Bumblebee 2021.1.1 Patch 3
- Firebase Component: Storage
- Component version: firebase-storage:20.0.1
[REQUIRED] Step 3: Describe the problem
StorageTask cannot be canceled while the network connection is unavailable.
Relevant Code:
suspend fun reproduceBug() {
// STEP 1 - turn off network connection (wifi/mobile)
val task = FirebaseStorage.getInstance()
.getReference("my-firebase-storage.json")
.getFile(File("my-file-pathname"))
task.addOnCanceledListener {
// even though task.cancel() returns true,
// listener will not be called until network connection gets established
}
task.addOnCompleteListener {
// even though task.cancel() returns true,
// listener will not be called until network connection gets established
}
delay(5000)
val isCanceled = task.cancel() // returns true, but not canceled
}
StorageTask goes into 'canceling' state: https://github.com/firebase/firebase-android-sdk/blob/f625c8c72aa6cca2429af3a0c67928fe37be9ffb/firebase-storage/src/main/java/com/google/firebase/storage/StorageTask.java#L50 ExponentialBackoffSender is stuck in the while loop, wasting resources, until it hits max-wait-time or network connection is established, because 'cancel' is not yet called. https://github.com/firebase/firebase-android-sdk/blob/f625c8c72aa6cca2429af3a0c67928fe37be9ffb/firebase-storage/src/main/java/com/google/firebase/storage/internal/ExponentialBackoffSender.java#L86 https://github.com/firebase/firebase-android-sdk/blob/f625c8c72aa6cca2429af3a0c67928fe37be9ffb/firebase-storage/src/main/java/com/google/firebase/storage/internal/ExponentialBackoffSender.java#L124
Thanks for reporting, @nikolajakshic. I was able to reproduce the same behavior. That being said, I'll notify an engineer to see what we can do here.
This is internally tracked in b/232059440. We'll post comments here once we get updates, thanks!