Skip to content

Commit aab779b

Browse files
elizarovrecheej
authored andcommitted
Fix logic that determines future removal for scheduled executors (Kotlin#1995)
I've failed to write a reliable test here. See also Kotlin#571 Fixes Kotlin#1992
1 parent c253929 commit aab779b

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)