Merge pull request #26744 from LK4D4/attach_before_start

libcontainerd: attach streams before create
This commit is contained in:
Victor Vieux 2016-09-26 13:08:05 -07:00 committed by GitHub
commit f67096c20b
2 changed files with 34 additions and 4 deletions

View file

@ -4507,3 +4507,15 @@ func (s *DockerDaemonSuite) TestRunWithUlimitAndDaemonDefault(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "[nofile=42:42]")
}
func (s *DockerSuite) TestRunStoppedLoggingDriverNoLeak(c *check.C) {
nroutines, err := getGoroutineNumber()
c.Assert(err, checker.IsNil)
out, _, err := dockerCmdWithError("run", "--name=fail", "--log-driver=splunk", "busybox", "true")
c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, "Failed to initialize logging driver", check.Commentf("error should be about logging driver, got output %s", out))
// NGoroutines is not updated right away, so we need to wait before failing
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
}

View file

@ -11,6 +11,7 @@ import (
"github.com/Sirupsen/logrus"
containerd "github.com/docker/containerd/api/grpc/types"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/restartmanager"
"github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
@ -91,11 +92,24 @@ func (ctr *container) start(checkpoint string, checkpointDir string) error {
if err != nil {
return nil
}
createChan := make(chan struct{})
iopipe, err := ctr.openFifos(spec.Process.Terminal)
if err != nil {
return err
}
// we need to delay stdin closure after container start or else "stdin close"
// event will be rejected by containerd.
// stdin closure happens in AttachStreams
stdin := iopipe.Stdin
iopipe.Stdin = ioutils.NewWriteCloserWrapper(stdin, func() error {
go func() {
<-createChan
stdin.Close()
}()
return nil
})
r := &containerd.CreateContainerRequest{
Id: ctr.containerID,
BundlePath: ctr.dir,
@ -111,17 +125,21 @@ func (ctr *container) start(checkpoint string, checkpointDir string) error {
}
ctr.client.appendContainer(ctr)
if err := ctr.client.backend.AttachStreams(ctr.containerID, *iopipe); err != nil {
close(createChan)
ctr.closeFifos(iopipe)
return err
}
resp, err := ctr.client.remote.apiClient.CreateContainer(context.Background(), r)
if err != nil {
close(createChan)
ctr.closeFifos(iopipe)
return err
}
ctr.startedAt = time.Now()
if err := ctr.client.backend.AttachStreams(ctr.containerID, *iopipe); err != nil {
return err
}
ctr.systemPid = systemPid(resp.Container)
close(createChan)
return ctr.client.backend.StateChanged(ctr.containerID, StateInfo{
CommonStateInfo: CommonStateInfo{