Skip to content

Commit 751364f

Browse files
committed
Workaround for KT-58685
1 parent 862b554 commit 751364f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

kotlinx-coroutines-core/common/src/sync/Mutex.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,14 @@ public suspend inline fun <T> Mutex.withLock(owner: Any? = null, action: () -> T
123123
}
124124

125125
lock(owner)
126-
try {
127-
return action()
128-
} finally {
126+
val result = try {
127+
action()
128+
} catch (e: Throwable) {
129129
unlock(owner)
130+
throw e
130131
}
132+
unlock(owner)
133+
return result
131134
}
132135

133136

kotlinx-coroutines-core/common/src/sync/Semaphore.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ public suspend inline fun <T> Semaphore.withPermit(action: () -> T): T {
8484
}
8585

8686
acquire()
87-
try {
88-
return action()
89-
} finally {
87+
val result = try {
88+
action()
89+
} catch (e: Throwable) {
9090
release()
91+
throw e
9192
}
93+
release()
94+
return result
9295
}
9396

9497
@Suppress("UNCHECKED_CAST")

0 commit comments

Comments
 (0)