Skip to content

Commit 98a3fad

Browse files
authored
Merge pull request #17472 from wordpress-mobile/issue/17463-prevent-invalid-mutex-unlock
Guard mutex unlock in isLocked check to avoid errors during local data uploads
2 parents c8dc643 + 749de37 commit 98a3fad

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)