diff --git a/packer/plugin/builder.go b/packer/plugin/builder.go index 47b342b42..b8999ff94 100644 --- a/packer/plugin/builder.go +++ b/packer/plugin/builder.go @@ -40,7 +40,7 @@ func (b *cmdBuilder) Cancel() { func (c *cmdBuilder) checkExit(p interface{}, cb func()) { if c.client.Exited() && cb != nil { cb() - } else if p != nil { + } else if p != nil && !Killed { log.Panic(p) } } diff --git a/packer/plugin/client.go b/packer/plugin/client.go index 94513a8e2..d4d87088a 100644 --- a/packer/plugin/client.go +++ b/packer/plugin/client.go @@ -20,6 +20,10 @@ import ( "unicode" ) +// If this is true, then the "unexpected EOF" panic will not be +// raised throughout the clients. +var Killed = false + // This is a slice of the "managed" clients which are cleaned up when // calling Cleanup var managedClients = make([]*Client, 0, 5) diff --git a/packer/plugin/command.go b/packer/plugin/command.go index 4d6ccc490..c47f7b549 100644 --- a/packer/plugin/command.go +++ b/packer/plugin/command.go @@ -45,7 +45,7 @@ func (c *cmdCommand) Synopsis() (result string) { func (c *cmdCommand) checkExit(p interface{}, cb func()) { if c.client.Exited() { cb() - } else if p != nil { + } else if p != nil && !Killed { log.Panic(p) } } diff --git a/packer/plugin/hook.go b/packer/plugin/hook.go index fd45585ea..90b0779d9 100644 --- a/packer/plugin/hook.go +++ b/packer/plugin/hook.go @@ -22,7 +22,7 @@ func (c *cmdHook) Run(name string, ui packer.Ui, comm packer.Communicator, data func (c *cmdHook) checkExit(p interface{}, cb func()) { if c.client.Exited() { cb() - } else if p != nil { + } else if p != nil && !Killed { log.Panic(p) } } diff --git a/packer/plugin/post_processor.go b/packer/plugin/post_processor.go index f511748a6..72398020f 100644 --- a/packer/plugin/post_processor.go +++ b/packer/plugin/post_processor.go @@ -31,7 +31,7 @@ func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer. func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) { if c.client.Exited() { cb() - } else if p != nil { + } else if p != nil && !Killed { log.Panic(p) } } diff --git a/packer/plugin/provisioner.go b/packer/plugin/provisioner.go index 66033b9d3..d990bc70b 100644 --- a/packer/plugin/provisioner.go +++ b/packer/plugin/provisioner.go @@ -31,7 +31,7 @@ func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) error func (c *cmdProvisioner) checkExit(p interface{}, cb func()) { if c.client.Exited() { cb() - } else if p != nil { + } else if p != nil && !Killed { log.Panic(p) } } diff --git a/signal.go b/signal.go index 2808bdf54..3d465ddbb 100644 --- a/signal.go +++ b/signal.go @@ -26,7 +26,9 @@ func setupSignalHandlers(env packer.Environment) { env.Ui().Error("Interrupt signal received twice. Forcefully exiting now.") - // Force kill all the plugins + // Force kill all the plugins, but mark that we're killing them + // first so that we don't get panics everywhere. + plugin.Killed = true plugin.CleanupClients() os.Exit(1) }()