[CORDA-2272]: Recovering from StackOverflowErrors and given time to async logger to flush. (#4323)

This commit is contained in:
Michele Sollecito 2018-11-29 13:20:28 +00:00 committed by GitHub
parent 34f581854b
commit 5d1652bacb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,7 @@ import org.apache.activemq.artemis.utils.ReusableLatch
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.slf4j.MDC
import java.time.Duration
import java.util.concurrent.TimeUnit
import kotlin.reflect.KProperty1
@ -221,8 +222,9 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
suspend(FlowIORequest.WaitForSessionConfirmations, maySkipCheckpoint = true)
Try.Success(result)
} catch (t: Throwable) {
if(t is VirtualMachineError) {
if(t.isUnrecoverable()) {
logger.error("Caught unrecoverable error from flow. Forcibly terminating the JVM, this might leave resources open, and most likely will.", t)
Thread.sleep(Duration.ofSeconds(10).toMillis()) // To allow async logger to flush.
Runtime.getRuntime().halt(1)
}
logger.info("Flow raised an error... sending it to flow hospital", t)
@ -287,6 +289,8 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
}
}
private fun Throwable.isUnrecoverable(): Boolean = this is VirtualMachineError && this !is StackOverflowError
/**
* If the sub-flow is [IdempotentFlow] we need to perform a checkpoint to make sure any potentially side-effect
* generating logic between the last checkpoint and the sub-flow invocation does not get replayed if the