Skip to content

Commit 38067db

Browse files
committed
Fix logic that determines future removal for scheduled executors
I've failed to write a reliable test here. See also #571 Fixes #1992
1 parent de38890 commit 38067db

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kotlinx-coroutines-core/jvm/src/internal/Concurrent.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ private val REMOVE_FUTURE_ON_CANCEL: Method? = try {
2929
@Suppress("NAME_SHADOWING")
3030
internal fun removeFutureOnCancel(executor: Executor): Boolean {
3131
try {
32-
val executor = executor as? ScheduledExecutorService ?: return false
32+
val executor = executor as? ScheduledThreadPoolExecutor ?: return false
3333
(REMOVE_FUTURE_ON_CANCEL ?: return false).invoke(executor, true)
3434
return true
3535
} catch (e: Throwable) {
36-
return true
36+
return false // failed to setRemoveOnCancelPolicy, assume it does not removes future on cancel
3737
}
3838
}

0 commit comments

Comments
 (0)