Fix cancellation check in AbstractKeepAliveNetworkHandlerSelector

This commit is contained in:
Him188 2021-07-31 16:11:34 +08:00
parent 978228afc1
commit 4a2b8ac92c

View File

@ -10,7 +10,10 @@
package net.mamoe.mirai.internal.network.handler.selector
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.*
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.yield
import net.mamoe.mirai.internal.network.handler.NetworkHandler
import net.mamoe.mirai.internal.network.handler.NetworkHandlerFactory
import net.mamoe.mirai.internal.network.handler.logger
@ -87,9 +90,7 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
// ?: MaxAttemptsReachedException(null)
}
if (!currentCoroutineContext().isActive) {
logIfEnabled { "Cancellation detected." }
yield() // throw canonical CancellationException if cancelled
throw CancellationException("Cancellation detected.")
yield() // check cancellation
}
val current = getCurrentInstanceOrNull()
lastNetwork = current