From f945cdc704d869bf9aa753f9e99c83d0da8a1b6b Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Tue, 1 Aug 2017 10:07:25 -0400 Subject: [PATCH] Update windows locking code Signed-off-by: Michael Crosby --- windows/process.go | 7 +++++++ windows/task.go | 16 ++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/windows/process.go b/windows/process.go index aa722b5de..e3c002527 100644 --- a/windows/process.go +++ b/windows/process.go @@ -89,6 +89,13 @@ func (p *process) ExitCode() (uint32, time.Time, error) { } func (p *process) Start(ctx context.Context) (err error) { + // If we fail, close the io right now + defer func() { + if err != nil { + p.io.Close() + } + }() + var hp hcsshim.Process if hp, err = p.task.hcsContainer.CreateProcess(p.conf); err != nil { return errors.Wrapf(err, "failed to create process") diff --git a/windows/task.go b/windows/task.go index 148a2ebf0..402847faa 100644 --- a/windows/task.go +++ b/windows/task.go @@ -104,17 +104,19 @@ func (t *task) Info() runtime.TaskInfo { func (t *task) Start(ctx context.Context) error { conf := newProcessConfig(t.spec.Process, t.io) - if _, err := t.newProcess(ctx, t.id, conf, t.io); err != nil { + p, err := t.newProcess(ctx, t.id, conf, t.io) + if err != nil { + return err + } + if err := p.Start(ctx); err != nil { return err } - t.publisher.Publish(ctx, runtime.TaskStartEventTopic, &eventsapi.TaskStart{ ContainerID: t.id, Pid: t.pid, }) - return nil } @@ -182,11 +184,6 @@ func (t *task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runt if pset, err = newPipeSet(ctx, opts.IO); err != nil { return nil, err } - defer func() { - if err != nil { - pset.Close() - } - }() conf := newProcessConfig(spec, pset) p, err := t.newProcess(ctx, id, conf, pset) @@ -284,8 +281,6 @@ func (t *task) newProcess(ctx context.Context, id string, conf *hcsshim.ProcessC } }() } - t.Unlock() - t.Lock() wp := &process{ id: id, pid: pid, @@ -293,6 +288,7 @@ func (t *task) newProcess(ctx context.Context, id string, conf *hcsshim.ProcessC status: runtime.CreatedStatus, task: t, exitCh: make(chan struct{}), + conf: conf, } t.processes[id] = wp t.Unlock()