Skip to content

Commit 749de37

Browse files
committed
Guard mutex unlock in isLocked check
This fix is applied to to prevent possible `IllegalStateException`s when the mutex is already unlocked by the system during a cancellation / completion while the locking function is suspended.
1 parent c8dc643 commit 749de37

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadStarter.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ class UploadStarter @Inject constructor(
178178
)
179179
}
180180
} finally {
181-
mutex.unlock()
181+
// If the job of the current coroutine is cancelled while the `lock()` call is suspended,
182+
// it results in the mutex ending up unlocked.
183+
// We introduced this check to prevent IllegalStateExceptions when `unlock` is called in those cases.
184+
// See: https://github.com/wordpress-mobile/WordPress-Android/issues/17463
185+
if (mutex.isLocked) {
186+
mutex.unlock()
187+
}
182188
}
183189
}
184190

0 commit comments

Comments
 (0)