Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix cri exec hang #2224

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions ctrd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,18 @@ func (c *Client) execContainer(ctx context.Context, process *Process) error {
exitTime: status.ExitTime(),
}

// run hook if not got fail here
if err := <-fail; err == nil {
for _, hook := range c.hooks {
if err := hook(process.ExecID, msg); err != nil {
logrus.Errorf("failed to execute the exec exit hooks: %v", err)
break
}
if err := <-fail; err != nil {
msg.err = err
// exit code should not be zero when exec get failed.
if msg.exitCode == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whether it is possible exitCode is not zero when exec got error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It possible, like exec $id aaaaa .

msg.exitCode = 126
}
}
// XXX: if exec process get run, io should be closed in this function,
for _, hook := range c.hooks {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, no matter run exec got an error or not, we always call the exit hook.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, when exec start , no matter what result, let hook do the clean. Before exec start, if got error, let pouch daemon level do the clean.

if err := hook(process.ExecID, msg); err != nil {
logrus.Errorf("failed to execute the exec exit hooks: %v", err)
break
}
}

Expand All @@ -141,7 +146,6 @@ func (c *Client) execContainer(ctx context.Context, process *Process) error {
// start the exec process
if err := execProcess.Start(ctx); err != nil {
fail <- err
return errors.Wrap(err, "failed to exec process")
}

return nil
Expand Down
14 changes: 10 additions & 4 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mgr
import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -34,6 +35,7 @@ import (
containerdtypes "github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/mount"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/libnetwork"
"github.com/go-openapi/strfmt"
"github.com/imdario/mergo"
Expand Down Expand Up @@ -1851,17 +1853,21 @@ func (mgr *ContainerManager) execExitedAndRelease(id string, m *ctrd.Message) er
execConfig.Running = false
execConfig.Error = m.RawError()

io := mgr.IOs.Get(id)
if io == nil {
eio := mgr.IOs.Get(id)
if eio == nil {
return nil
}

if err := m.RawError(); err != nil {
fmt.Fprintf(io.Stdout, "%v\n", err)
var stdout io.Writer = eio.Stdout
if !execConfig.Tty && !eio.MuxDisabled {
stdout = stdcopy.NewStdWriter(stdout, stdcopy.Stdout)
}
stdout.Write([]byte(err.Error() + "\r\n"))
}

// close io
io.Close()
eio.Close()
mgr.IOs.Remove(id)

return nil
Expand Down