mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-27 16:12:48 +08:00
Fix HB logic: catch TimeoutCancellationException from HB action and report it as non-fatal error. Fix #2024
This commit is contained in:
parent
71fb5585fe
commit
0d3bc9c684
@ -114,18 +114,26 @@ internal class TimeBasedHeartbeatSchedulerImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val result = withTimeoutOrNull(timeout()) { action() }
|
var cause: Throwable? = null
|
||||||
|
val result = try {
|
||||||
|
withTimeoutOrNull(timeout()) { action() }
|
||||||
|
} catch (e: TimeoutCancellationException) {
|
||||||
|
// from `action`
|
||||||
|
cause = e
|
||||||
|
null
|
||||||
|
}
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
onHeartFailure(
|
onHeartFailure(
|
||||||
name,
|
name,
|
||||||
PacketTimeoutException(
|
PacketTimeoutException(
|
||||||
"$coroutineName: Timeout receiving action response",
|
"$coroutineName: Timeout receiving action response",
|
||||||
CancellationException("Dummy exception for stacktrace")
|
cause
|
||||||
) // This is a NetworkException that is recoverable
|
) // This is a NetworkException that is recoverable
|
||||||
)
|
)
|
||||||
return@async
|
return@async
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
// catch other errors
|
||||||
onHeartFailure(
|
onHeartFailure(
|
||||||
name,
|
name,
|
||||||
IllegalStateException("$coroutineName: Internal error: caught unexpected exception", e)
|
IllegalStateException("$coroutineName: Internal error: caught unexpected exception", e)
|
||||||
|
Loading…
Reference in New Issue
Block a user