Skip to content

Commit c3ab67a

Browse files
committed
Fix: wrap mutex lock/unlock in try/catch block
1 parent 9f0a4c0 commit c3ab67a

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,27 @@ class UploadStarter @Inject constructor(
126126
* This is meant to be used by [checkConnectionAndUpload] only.
127127
*/
128128
private suspend fun upload(site: SiteModel) = coroutineScope {
129-
mutex.withLock {
130-
val posts = async { postStore.getPostsWithLocalChanges(site) }
131-
val pages = async { pageStore.getPagesWithLocalChanges(site) }
132-
val list = posts.await() + pages.await()
133-
list.asSequence()
134-
.map { post ->
135-
val action = uploadActionUseCase.getAutoUploadAction(post, site)
136-
Pair(post, action)
137-
}
138-
.filter { (_, action) -> action != DO_NOTHING }
139-
.toList()
140-
.forEach { (post, action) ->
141-
runCatching {
129+
try {
130+
mutex.withLock {
131+
val posts = async { postStore.getPostsWithLocalChanges(site).orEmpty() }
132+
val pages = async { (pageStore.getPagesWithLocalChanges(site) as? List<PostModel>).orEmpty() }
133+
val list = posts.await() + pages.await()
134+
list.asSequence()
135+
.map { post ->
136+
val action = uploadActionUseCase.getAutoUploadAction(post, site)
137+
Pair(post, action)
138+
}
139+
.filter { (_, action) -> action != DO_NOTHING }
140+
.toList()
141+
.forEach { (post, action) ->
142142
trackAutoUploadAction(action, post.status, post.isPage)
143143
AppLog.d(T.POSTS, "UploadStarter for ${post.toStringLog()}; action: $action")
144144
dispatcher.dispatch(UploadActionBuilder.newIncrementNumberOfAutoUploadAttemptsAction(post))
145145
uploadServiceFacade.uploadPost(appContext, post, trackAnalytics = false)
146-
}.onFailure {
147-
AppLog.e(T.POSTS, it)
148146
}
149-
}
147+
}
148+
} catch (e: Exception) {
149+
AppLog.e(T.POSTS, e)
150150
}
151151
}
152152

0 commit comments

Comments
 (0)