From b52c52378f45ca4506363f878ee1e7d96081c4b6 Mon Sep 17 00:00:00 2001 From: "rick.parker" Date: Fri, 9 Dec 2016 09:21:59 +0000 Subject: [PATCH] Move Future completion outside database transaction so that the effects of the flow will be externally visible at Future completion. --- .../node/services/statemachine/FlowStateMachineImpl.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt index c929cb6319..3d2cff0cc5 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt @@ -86,15 +86,16 @@ class FlowStateMachineImpl(override val id: StateMachineRunId, val result = try { logic.call() } catch (t: Throwable) { - processException(t) + actionOnEnd() commitTransaction() + _resultFuture?.setException(t) throw ExecutionException(t) } // This is to prevent actionOnEnd being called twice if it throws an exception actionOnEnd() - _resultFuture?.set(result) commitTransaction() + _resultFuture?.set(result) return result } @@ -264,8 +265,8 @@ class FlowStateMachineImpl(override val id: StateMachineRunId, // This can get called in actionOnSuspend *after* we commit the database transaction, so optionally open a new one here. databaseTransaction(database) { actionOnEnd() - _resultFuture?.setException(t) } + _resultFuture?.setException(t) } internal fun resume(scheduler: FiberScheduler) {