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

bugfix: disable mux stdout and stderr if backend is not http #1250

Merged
merged 1 commit into from
Apr 28, 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
2 changes: 1 addition & 1 deletion ctrd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *Client) ExecContainer(ctx context.Context, process *Process) error {
pStderr io.Writer = process.IO.Stderr
)

if !process.P.Terminal {
if !process.P.Terminal && !process.IO.MuxDisabled {
pStdout = stdcopy.NewStdWriter(pStdout, stdcopy.Stdout)
pStderr = stdcopy.NewStdWriter(pStderr, stdcopy.Stderr)
}
Expand Down
11 changes: 9 additions & 2 deletions daemon/containerio/container_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ type IO struct {
Stdout *ContainerIO
Stderr *ContainerIO
Stdin *ContainerIO

// For IO backend like http, we need to mux stdout & stderr
// if terminal is disabled.
// But for other IO backend, it is not necessary.
// So we should make it configurable.
MuxDisabled bool
}

// NewIO creates the container's ios of stdout, stderr, stdin.
func NewIO(opt *Option) *IO {
backends := createBackend(opt)

i := &IO{
Stdout: create(opt, stdout, backends),
Stderr: create(opt, stderr, backends),
Stdout: create(opt, stdout, backends),
Stderr: create(opt, stderr, backends),
MuxDisabled: opt.muxDisabled,
}

if opt.stdin {
Expand Down
8 changes: 8 additions & 0 deletions daemon/containerio/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Option struct {
id string
rootDir string
stdin bool
muxDisabled bool
backends map[string]struct{}
hijack http.Hijacker
hijackUpgrade bool
Expand Down Expand Up @@ -54,6 +55,13 @@ func WithStdin(stdin bool) func(*Option) {
}
}

// WithMuxDisabled specified whether mux stdout & stderr of container IO.
func WithMuxDisabled(muxDisabled bool) func(*Option) {
return func(opt *Option) {
opt.muxDisabled = muxDisabled
}
}

// WithDiscard specified the discard backend.
func WithDiscard() func(*Option) {
return func(opt *Option) {
Expand Down
1 change: 1 addition & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ func (mgr *ContainerManager) openExecIO(id string, attach *AttachConfig) (*conta
options := []func(*containerio.Option){
containerio.WithID(id),
containerio.WithStdin(attach.Stdin),
containerio.WithMuxDisabled(attach.MuxDisabled),
}

if attach != nil {
Expand Down
6 changes: 6 additions & 0 deletions daemon/mgr/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ type AttachConfig struct {
Stdout bool
Stderr bool

// For IO backend like http, we need to mux stdout & stderr
// if terminal is disabled.
// But for other IO backend, it is not necessary.
// So we should make it configurable.
MuxDisabled bool

// Attach using http.
Hijack http.Hijacker
Upgrade bool
Expand Down
7 changes: 4 additions & 3 deletions daemon/mgr/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,10 @@ func (c *CriManager) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (
var output bytes.Buffer
startConfig := &apitypes.ExecStartConfig{}
attachConfig := &AttachConfig{
Stdout: true,
Stderr: true,
MemBuffer: &output,
Stdout: true,
Stderr: true,
MemBuffer: &output,
MuxDisabled: true,
}

err = c.ContainerMgr.StartExec(ctx, execid, startConfig, attachConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use pipeIO to check the status? I think that the spin check is not good for the performance.

BTW, if the cmd is top, the timeout can work with the io.Copy.

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, it's ugly actually, I'll make it more elegant in the future.

Thanks for your advice.

Copy link
Collaborator

@allencloud allencloud Apr 28, 2018

Choose a reason for hiding this comment

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

Could you add an issue to record this? @fuweid
Or @YaoZengzeng you to add this issue?
And thanks for the test fixing.

Copy link
Contributor

Choose a reason for hiding this comment

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

@allencloud @YaoZengzeng I will add the issue for this. Thanks

Expand Down
3 changes: 2 additions & 1 deletion daemon/mgr/cri_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (s *streamRuntime) Exec(containerID string, cmd []string, streamOpts *remot

startConfig := &apitypes.ExecStartConfig{}
attachConfig := &AttachConfig{
Streams: streams,
Streams: streams,
MuxDisabled: true,
}

err = s.containerMgr.StartExec(ctx, execid, startConfig, attachConfig)
Expand Down
2 changes: 1 addition & 1 deletion hack/cri-test/test-cri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ POUCH_SOCK="/var/run/pouchcri.sock"
CRI_FOCUS=${CRI_FOCUS:-}

# CRI_SKIP skips the test to skip.
CRI_SKIP=${CRI_SKIP:-"RunAsUserName|seccomp localhost|should error on create with wrong options|runtime should support RunAsUser|should support safe sysctls|runtime should support exec|runtime should support HostPID|runtime should support execSync|should support unsafe sysctls"}
CRI_SKIP=${CRI_SKIP:-"RunAsUserName|seccomp localhost|should error on create with wrong options"}
# REPORT_DIR is the the directory to store test logs.
REPORT_DIR=${REPORT_DIR:-"/tmp/test-cri"}

Expand Down