diff --git a/agent.go b/agent.go index ec01250695..a529a17770 100644 --- a/agent.go +++ b/agent.go @@ -58,6 +58,8 @@ var initRootfsMounts = []initMount{ } type process struct { + sync.RWMutex + id string process libcontainer.Process stdin *os.File @@ -66,6 +68,7 @@ type process struct { consoleSock *os.File termMaster *os.File exitCodeCh chan int + stdinClosed bool } type container struct { diff --git a/grpc.go b/grpc.go index 37f9f2d96c..4937054525 100644 --- a/grpc.go +++ b/grpc.go @@ -1044,6 +1044,16 @@ func (a *agentGRPC) WriteStdin(ctx context.Context, req *pb.WriteStreamRequest) return &pb.WriteStreamResponse{}, err } + proc.RLock() + defer proc.RUnlock() + stdinClosed := proc.stdinClosed + + // Ignore this call to WriteStdin() if STDIN has already been closed + // earlier. + if stdinClosed { + return &pb.WriteStreamResponse{}, nil + } + var file *os.File if proc.termMaster != nil { file = proc.termMaster @@ -1095,10 +1105,15 @@ func (a *agentGRPC) CloseStdin(ctx context.Context, req *pb.CloseStdinRequest) ( return emptyResp, nil } + proc.Lock() + defer proc.Unlock() + if err := proc.stdin.Close(); err != nil { return emptyResp, err } + proc.stdinClosed = true + return emptyResp, nil }