[CORDA-1542]: Ctrl-C in the shell no longer aborts the flow (fix). (#3260)

This commit is contained in:
Michele Sollecito 2018-05-30 10:29:10 +01:00 committed by GitHub
parent 202bd6603b
commit 1c1b492532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View File

@ -7,6 +7,8 @@ release, see :doc:`upgrade-notes`.
Unreleased
==========
* Shell now kills an ongoing flow when CTRL+C is pressed in the terminal.
* ``ServiceHub`` and ``CordaRPCOps`` can now safely be used from multiple threads without incurring in database transaction problems.
* Doorman and NetworkMap url's can now be configured individually rather than being assumed to be

View File

@ -15,10 +15,18 @@ import net.corda.core.CordaException
import net.corda.core.concurrent.CordaFuture
import net.corda.core.contracts.UniqueIdentifier
import net.corda.core.flows.FlowLogic
import net.corda.core.internal.*
import net.corda.core.internal.Emoji
import net.corda.core.internal.concurrent.doneFuture
import net.corda.core.internal.concurrent.openFuture
import net.corda.core.messaging.*
import net.corda.core.internal.createDirectories
import net.corda.core.internal.div
import net.corda.core.internal.rootCause
import net.corda.core.internal.uncheckedCast
import net.corda.core.messaging.CordaRPCOps
import net.corda.core.messaging.DataFeed
import net.corda.core.messaging.FlowProgressHandle
import net.corda.core.messaging.StateMachineUpdate
import net.corda.core.messaging.pendingFlowsCount
import net.corda.tools.shell.utlities.ANSIProgressRenderer
import net.corda.tools.shell.utlities.StdoutANSIProgressRenderer
import org.crsh.command.InvocationContext
@ -268,12 +276,19 @@ object InteractiveShell {
val latch = CountDownLatch(1)
ansiProgressRenderer.render(stateObservable, { latch.countDown() })
try {
// Wait for the flow to end and the progress tracker to notice. By the time the latch is released
// the tracker is done with the screen.
latch.await()
} catch (e: InterruptedException) {
// TODO: When the flow framework allows us to kill flows mid-flight, do so here.
// Wait for the flow to end and the progress tracker to notice. By the time the latch is released
// the tracker is done with the screen.
while (!Thread.currentThread().isInterrupted) {
try {
latch.await()
} catch (e: InterruptedException) {
try {
rpcOps.killFlow(stateObservable.id)
} finally {
Thread.currentThread().interrupt()
break
}
}
}
stateObservable.returnValue.get()?.apply {
if (this !is Throwable) {