Skip to content

Refactor TerminalLogURI() to Support Optional Stderr Configuration for Terminal Compatibility on Windows #10415

@TinaMor

Description

@TinaMor

Discussed in #10380

Originally posted by TinaMor June 24, 2024
Windows requires that stderr is an empty string when running a container with TTY. In Containerd, pkg/cio/io.go#L298-L302, the Stderr is set to a value, e.g.

res = "binary:///C:/_xxx_/nerdctl.exe?_NERDCTL_INTERNAL_LOGGING=C%3A%5CProgramData%5Cnerdctl%5C052055e3"

which causes microsoft/hcsshim service_internal.go#L127 to fail to create a new task.

containerd/pkg/cio/io.go

Lines 298 to 302 in 4a18adc

config: Config{
Stdout: res,
Stderr: res,
Terminal: true,
},

To address this issue related to nerdctl, we can refactor the TerminalLogURI() function. This will involve adding an optional parameter that specifies whether stderr should be set to an empty string when the terminal is used. This change will help avoid the "failed precondition" error when creating a new task on Windows.

Example:

func TerminalLogURI(uri *url.URL, setStderr ...bool) Creator {
	return func(_ string) (IO, error) {
		// Default value for Stderr is an ampty string
		stderr := ""
        
		if len(setStderr) > 0 && setStderr[0] {
			stderr = uri.String()
		}

		return &logURI{
			config: Config{
				Stdout:   uri.String(),
				Stderr:   stderr,
				Terminal: true,
			},
		}, nil
	}
}

Related issues:

nerdctl bug #2966

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions