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 { 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)