浏览代码

Merge pull request #38383 from tonistiigi/exec-ctx

libcontainerd: prevent exec delete locking
Sebastiaan van Stijn 6 年之前
父节点
当前提交
8422e6f6fa
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      libcontainerd/client_daemon.go

+ 7 - 2
libcontainerd/client_daemon.go

@@ -29,7 +29,7 @@ import (
 	"github.com/containerd/typeurl"
 	"github.com/containerd/typeurl"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/pkg/ioutils"
 	"github.com/docker/docker/pkg/ioutils"
-	"github.com/opencontainers/image-spec/specs-go/v1"
+	v1 "github.com/opencontainers/image-spec/specs-go/v1"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
@@ -384,7 +384,12 @@ func (c *client) Exec(ctx context.Context, containerID, processID string, spec *
 	defer close(stdinCloseSync)
 	defer close(stdinCloseSync)
 
 
 	if err = p.Start(ctx); err != nil {
 	if err = p.Start(ctx); err != nil {
-		p.Delete(context.Background())
+		// use new context for cleanup because old one may be cancelled by user, but leave a timeout to make sure
+		// we are not waiting forever if containerd is unresponsive or to work around fifo cancelling issues in
+		// older containerd-shim
+		ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
+		defer cancel()
+		p.Delete(ctx)
 		ctr.deleteProcess(processID)
 		ctr.deleteProcess(processID)
 		return -1, wrapError(err)
 		return -1, wrapError(err)
 	}
 	}