Move the wait result to bottom of methods

This commit is contained in:
Alex Dadgar
2016-11-04 14:58:55 -07:00
parent 16d1fede7d
commit 12c033ab81
6 changed files with 38 additions and 20 deletions

View File

@@ -1156,6 +1156,7 @@ func (h *DockerHandle) run() {
}
}
// Send the results
h.waitCh <- dstructs.NewWaitResult(exitCode, 0, werr)
close(h.waitCh)
}

View File

@@ -304,7 +304,7 @@ func (h *execHandle) Stats() (*cstructs.TaskResourceUsage, error) {
}
func (h *execHandle) run() {
ps, err := h.executor.Wait()
ps, werr := h.executor.Wait()
close(h.doneCh)
// If the exitcode is 0 and we had an error that means the plugin didn't
@@ -312,7 +312,7 @@ func (h *execHandle) run() {
// the user process so that when we create a new executor on restarting the
// new user process doesn't have collisions with resources that the older
// user pid might be holding onto.
if ps.ExitCode == 0 && err != nil {
if ps.ExitCode == 0 && werr != nil {
if h.isolationConfig != nil {
ePid := h.pluginClient.ReattachConfig().Pid
if e := executor.ClientCleanup(h.isolationConfig, ePid); e != nil {
@@ -323,15 +323,19 @@ func (h *execHandle) run() {
h.logger.Printf("[ERR] driver.exec: unmounting dev,proc and alloc dirs failed: %v", e)
}
}
h.waitCh <- dstructs.NewWaitResult(ps.ExitCode, ps.Signal, err)
close(h.waitCh)
// Remove services
if err := h.executor.DeregisterServices(); err != nil {
h.logger.Printf("[ERR] driver.exec: failed to deregister services: %v", err)
}
// Exit the executor
if err := h.executor.Exit(); err != nil {
h.logger.Printf("[ERR] driver.exec: error destroying executor: %v", err)
}
h.pluginClient.Kill()
// Send the results
h.waitCh <- dstructs.NewWaitResult(ps.ExitCode, ps.Signal, werr)
close(h.waitCh)
}

View File

@@ -404,9 +404,9 @@ func (h *javaHandle) Stats() (*cstructs.TaskResourceUsage, error) {
}
func (h *javaHandle) run() {
ps, err := h.executor.Wait()
ps, werr := h.executor.Wait()
close(h.doneCh)
if ps.ExitCode == 0 && err != nil {
if ps.ExitCode == 0 && werr != nil {
if h.isolationConfig != nil {
ePid := h.pluginClient.ReattachConfig().Pid
if e := executor.ClientCleanup(h.isolationConfig, ePid); e != nil {
@@ -421,14 +421,17 @@ func (h *javaHandle) run() {
h.logger.Printf("[ERR] driver.java: unmounting dev,proc and alloc dirs failed: %v", e)
}
}
h.waitCh <- &dstructs.WaitResult{ExitCode: ps.ExitCode, Signal: ps.Signal, Err: err}
close(h.waitCh)
// Remove services
if err := h.executor.DeregisterServices(); err != nil {
h.logger.Printf("[ERR] driver.java: failed to kill the deregister services: %v", err)
}
// Exit the executor
h.executor.Exit()
h.pluginClient.Kill()
// Send the results
h.waitCh <- &dstructs.WaitResult{ExitCode: ps.ExitCode, Signal: ps.Signal, Err: werr}
close(h.waitCh)
}

View File

@@ -407,8 +407,8 @@ func (h *qemuHandle) Stats() (*cstructs.TaskResourceUsage, error) {
}
func (h *qemuHandle) run() {
ps, err := h.executor.Wait()
if ps.ExitCode == 0 && err != nil {
ps, werr := h.executor.Wait()
if ps.ExitCode == 0 && werr != nil {
if e := killProcess(h.userPid); e != nil {
h.logger.Printf("[ERR] driver.qemu: error killing user process: %v", e)
}
@@ -417,13 +417,17 @@ func (h *qemuHandle) run() {
}
}
close(h.doneCh)
h.waitCh <- &dstructs.WaitResult{ExitCode: ps.ExitCode, Signal: ps.Signal, Err: err}
close(h.waitCh)
// Remove services
if err := h.executor.DeregisterServices(); err != nil {
h.logger.Printf("[ERR] driver.qemu: failed to deregister services: %v", err)
}
// Exit the executor
h.executor.Exit()
h.pluginClient.Kill()
// Send the results
h.waitCh <- &dstructs.WaitResult{ExitCode: ps.ExitCode, Signal: ps.Signal, Err: werr}
close(h.waitCh)
}

View File

@@ -299,9 +299,9 @@ func (h *rawExecHandle) Stats() (*cstructs.TaskResourceUsage, error) {
}
func (h *rawExecHandle) run() {
ps, err := h.executor.Wait()
ps, werr := h.executor.Wait()
close(h.doneCh)
if ps.ExitCode == 0 && err != nil {
if ps.ExitCode == 0 && werr != nil {
if e := killProcess(h.userPid); e != nil {
h.logger.Printf("[ERR] driver.raw_exec: error killing user process: %v", e)
}
@@ -309,15 +309,18 @@ func (h *rawExecHandle) run() {
h.logger.Printf("[ERR] driver.raw_exec: unmounting dev,proc and alloc dirs failed: %v", e)
}
}
h.waitCh <- &dstructs.WaitResult{ExitCode: ps.ExitCode, Signal: ps.Signal, Err: err}
close(h.waitCh)
// Remove services
if err := h.executor.DeregisterServices(); err != nil {
h.logger.Printf("[ERR] driver.raw_exec: failed to deregister services: %v", err)
}
// Exit the executor
if err := h.executor.Exit(); err != nil {
h.logger.Printf("[ERR] driver.raw_exec: error killing executor: %v", err)
}
h.pluginClient.Kill()
// Send the results
h.waitCh <- &dstructs.WaitResult{ExitCode: ps.ExitCode, Signal: ps.Signal, Err: werr}
close(h.waitCh)
}

View File

@@ -544,9 +544,9 @@ func (h *rktHandle) Stats() (*cstructs.TaskResourceUsage, error) {
}
func (h *rktHandle) run() {
ps, err := h.executor.Wait()
ps, werr := h.executor.Wait()
close(h.doneCh)
if ps.ExitCode == 0 && err != nil {
if ps.ExitCode == 0 && werr != nil {
if e := killProcess(h.executorPid); e != nil {
h.logger.Printf("[ERROR] driver.rkt: error killing user process: %v", e)
}
@@ -554,15 +554,18 @@ func (h *rktHandle) run() {
h.logger.Printf("[ERROR] driver.rkt: unmounting dev,proc and alloc dirs failed: %v", e)
}
}
h.waitCh <- dstructs.NewWaitResult(ps.ExitCode, 0, err)
close(h.waitCh)
// Remove services
if err := h.executor.DeregisterServices(); err != nil {
h.logger.Printf("[ERR] driver.rkt: failed to deregister services: %v", err)
}
// Exit the executor
if err := h.executor.Exit(); err != nil {
h.logger.Printf("[ERR] driver.rkt: error killing executor: %v", err)
}
h.pluginClient.Kill()
// Send the results
h.waitCh <- dstructs.NewWaitResult(ps.ExitCode, 0, werr)
close(h.waitCh)
}