From 3879a875ccc79aee5f0effca4e030aece61c3a41 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 4 Sep 2018 15:48:38 -0700 Subject: [PATCH] Fix device launcher ctx cleanup --- plugins/shared/cmd/launcher/command/device.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/shared/cmd/launcher/command/device.go b/plugins/shared/cmd/launcher/command/device.go index 53731945b..1f276c125 100644 --- a/plugins/shared/cmd/launcher/command/device.go +++ b/plugins/shared/cmd/launcher/command/device.go @@ -260,14 +260,27 @@ func (c *Device) startRepl() error { c.Ui.Output("> Availabile commands are: exit(), fingerprint(), stop_fingerprint(), stats(), stop_stats(), reserve(id1, id2, ...)") var fingerprintCtx, statsCtx context.Context var fingerprintCancel, statsCancel context.CancelFunc + for { in, err := c.Ui.Ask("> ") if err != nil { + if fingerprintCancel != nil { + fingerprintCancel() + } + if statsCancel != nil { + statsCancel() + } return err } switch { case in == "exit()": + if fingerprintCancel != nil { + fingerprintCancel() + } + if statsCancel != nil { + statsCancel() + } return nil case in == "fingerprint()": if fingerprintCtx != nil { @@ -301,8 +314,6 @@ func (c *Device) startRepl() error { c.Ui.Error(fmt.Sprintf("> Unknown command %q", in)) } } - - return nil } func (c *Device) replOutput(ctx context.Context, startFingerprint, startStats <-chan context.Context, reserve <-chan []string) {