From ddba35eade822d6234b0c95569c6a56b1795785d Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Wed, 10 Oct 2018 14:54:00 +0800 Subject: [PATCH] bugfix: wait for stdin creation before CloseIO The stdin fifo of exec process is created in containerd side after client calls Start. If the client calls CloseIO before Start call, the stdin of exec process is still opened and wait for close. For this case, client closes stdinCloseSync channel after Start. Signed-off-by: Wei Fu (cherry picked from commit c7890f25a9eaae8d07614bd85b2b3231b03e54ec) Signed-off-by: Sebastiaan van Stijn Upstream-commit: 6679a5faeb724f1ad060f2fdf6d189f1005924b9 Component: engine --- components/engine/libcontainerd/client_daemon.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/engine/libcontainerd/client_daemon.go b/components/engine/libcontainerd/client_daemon.go index 60fb3353c1..cb9cb43a73 100644 --- a/components/engine/libcontainerd/client_daemon.go +++ b/components/engine/libcontainerd/client_daemon.go @@ -328,6 +328,13 @@ func (c *client) Start(ctx context.Context, id, checkpointDir string, withStdin return int(t.Pid()), nil } +// Exec creates exec process. +// +// The containerd client calls Exec to register the exec config in the shim side. +// When the client calls Start, the shim will create stdin fifo if needs. But +// for the container main process, the stdin fifo will be created in Create not +// the Start call. stdinCloseSync channel should be closed after Start exec +// process. func (c *client) Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error) { ctr := c.getContainer(containerID) if ctr == nil { @@ -372,7 +379,9 @@ func (c *client) Exec(ctx context.Context, containerID, processID string, spec * ctr.addProcess(processID, p) // Signal c.createIO that it can call CloseIO - close(stdinCloseSync) + // + // the stdin of exec process will be created after p.Start in containerd + defer close(stdinCloseSync) if err = p.Start(ctx); err != nil { p.Delete(context.Background())