mirror of
https://github.com/corda/corda.git
synced 2025-02-20 17:33:15 +00:00
[CORDA-2272]: Recovering from StackOverflowErrors and given time to async logger to flush. (#4323)
This commit is contained in:
parent
34f581854b
commit
5d1652bacb
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user