From 6b2a8b44b2975cbb45e0f68b9eea973029868563 Mon Sep 17 00:00:00 2001 From: Zou Rui <21751189@zju.edu.cn> Date: Wed, 16 May 2018 18:03:27 +0800 Subject: [PATCH] bugfix: move IO part behind to ensure execConfig result assignment before IO closes Signed-off-by: Zou Rui <21751189@zju.edu.cn> --- daemon/mgr/container.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/daemon/mgr/container.go b/daemon/mgr/container.go index 38c261b01..579ac4846 100644 --- a/daemon/mgr/container.go +++ b/daemon/mgr/container.go @@ -95,7 +95,7 @@ type ContainerMgr interface { // Remove removes a container, it may be running or stopped and so on. Remove(ctx context.Context, name string, option *types.ContainerRemoveOptions) error - // 2. The following five functions is related to containr exec. + // 2. The following five functions is related to container exec. // CreateExec creates exec process's environment. CreateExec(ctx context.Context, name string, config *types.ExecCreateConfig) (string, error) @@ -1674,16 +1674,6 @@ func (mgr *ContainerManager) exitedAndRelease(id string, m *ctrd.Message) error // execExitedAndRelease be register into ctrd as a callback function, when the exec process in a container // exited, "ctrd" will call it to release resource and so on. func (mgr *ContainerManager) execExitedAndRelease(id string, m *ctrd.Message) error { - if io := mgr.IOs.Get(id); io != nil { - if err := m.RawError(); err != nil { - fmt.Fprintf(io.Stdout, "%v\n", err) - } - - // close io - io.Close() - mgr.IOs.Remove(id) - } - v, ok := mgr.ExecProcesses.Get(id).Result() if !ok { return errors.Wrap(errtypes.ErrNotfound, "to be exec process: "+id) @@ -1696,7 +1686,16 @@ func (mgr *ContainerManager) execExitedAndRelease(id string, m *ctrd.Message) er execConfig.Running = false execConfig.Error = m.RawError() - // TODO: GC invalid mgr.ExecProcess. + if io := mgr.IOs.Get(id); io != nil { + if err := m.RawError(); err != nil { + fmt.Fprintf(io.Stdout, "%v\n", err) + } + + // close io + io.Close() + mgr.IOs.Remove(id) + } + return nil }