Fix HB logic: catch TimeoutCancellationException from HB action and report it as non-fatal error. Fix #2024

This commit is contained in:
Him188 2022-05-09 08:58:47 +01:00
parent 71fb5585fe
commit 0d3bc9c684

View File

@ -114,18 +114,26 @@ internal class TimeBasedHeartbeatSchedulerImpl(
}
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) {
onHeartFailure(
name,
PacketTimeoutException(
"$coroutineName: Timeout receiving action response",
CancellationException("Dummy exception for stacktrace")
cause
) // This is a NetworkException that is recoverable
)
return@async
}
} catch (e: Throwable) {
// catch other errors
onHeartFailure(
name,
IllegalStateException("$coroutineName: Internal error: caught unexpected exception", e)