Commit f68e0008 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: Killed bool to avoid panics when killing clients

parent 8b00c828
...@@ -40,7 +40,7 @@ func (b *cmdBuilder) Cancel() { ...@@ -40,7 +40,7 @@ func (b *cmdBuilder) Cancel() {
func (c *cmdBuilder) checkExit(p interface{}, cb func()) { func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil { if c.client.Exited() && cb != nil {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }
...@@ -20,6 +20,10 @@ import ( ...@@ -20,6 +20,10 @@ import (
"unicode" "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 // This is a slice of the "managed" clients which are cleaned up when
// calling Cleanup // calling Cleanup
var managedClients = make([]*Client, 0, 5) var managedClients = make([]*Client, 0, 5)
......
...@@ -45,7 +45,7 @@ func (c *cmdCommand) Synopsis() (result string) { ...@@ -45,7 +45,7 @@ func (c *cmdCommand) Synopsis() (result string) {
func (c *cmdCommand) checkExit(p interface{}, cb func()) { func (c *cmdCommand) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }
...@@ -22,7 +22,7 @@ func (c *cmdHook) Run(name string, ui packer.Ui, comm packer.Communicator, data ...@@ -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()) { func (c *cmdHook) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }
...@@ -31,7 +31,7 @@ func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer. ...@@ -31,7 +31,7 @@ func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) { func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }
...@@ -31,7 +31,7 @@ func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) error ...@@ -31,7 +31,7 @@ func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) error
func (c *cmdProvisioner) checkExit(p interface{}, cb func()) { func (c *cmdProvisioner) checkExit(p interface{}, cb func()) {
if c.client.Exited() { if c.client.Exited() {
cb() cb()
} else if p != nil { } else if p != nil && !Killed {
log.Panic(p) log.Panic(p)
} }
} }
...@@ -26,7 +26,9 @@ func setupSignalHandlers(env packer.Environment) { ...@@ -26,7 +26,9 @@ func setupSignalHandlers(env packer.Environment) {
env.Ui().Error("Interrupt signal received twice. Forcefully exiting now.") 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() plugin.CleanupClients()
os.Exit(1) os.Exit(1)
}() }()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment