Skip to content

Commit bc1ff51

Browse files
committed
Don't block on STDIN open
This was found testing other runtime shims that are faster than runc(no containerization). This is a race that can cause the shim to block forever. It's not an issue for out/err because we open both sides of the pipe, but for stdin, it expects the client to have it opened. Signed-off-by: Michael Crosby <[email protected]>
1 parent 6b00aaa commit bc1ff51

4 files changed

Lines changed: 5 additions & 12 deletions

File tree

runtime/v1/linux/proc/exec.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ func (e *execProcess) start(ctx context.Context) (err error) {
164164
return e.parent.runtimeError(err, "OCI runtime exec failed")
165165
}
166166
if e.stdio.Stdin != "" {
167-
fifoCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
168-
defer cancel()
169-
170-
sc, err := fifo.OpenFifo(fifoCtx, e.stdio.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
167+
sc, err := fifo.OpenFifo(ctx, e.stdio.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
171168
if err != nil {
172169
return errors.Wrapf(err, "failed to open stdin fifo %s", e.stdio.Stdin)
173170
}
@@ -184,10 +181,7 @@ func (e *execProcess) start(ctx context.Context) (err error) {
184181
return errors.Wrap(err, "failed to start console copy")
185182
}
186183
} else if !e.stdio.IsNull() {
187-
fifoCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
188-
defer cancel()
189-
190-
if err := copyPipes(fifoCtx, e.io, e.stdio.Stdin, e.stdio.Stdout, e.stdio.Stderr, &e.wg, &copyWaitGroup); err != nil {
184+
if err := copyPipes(ctx, e.io, e.stdio.Stdin, e.stdio.Stdout, e.stdio.Stderr, &e.wg, &copyWaitGroup); err != nil {
191185
return errors.Wrap(err, "failed to start io pipe copy")
192186
}
193187
}

runtime/v1/linux/proc/io.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w
112112
rio.Stdin().Close()
113113
return nil
114114
}
115-
f, err := fifo.OpenFifo(ctx, stdin, syscall.O_RDONLY, 0)
115+
f, err := fifo.OpenFifo(ctx, stdin, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
116116
if err != nil {
117117
return fmt.Errorf("containerd-shim: opening %s failed: %s", stdin, err)
118118
}

runtime/v2/runc/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ type service struct {
9898
ec chan runcC.Exit
9999
ep *epoller
100100

101-
id string
102-
// Filled by Create()
101+
id string
103102
bundle string
104103
cg cgroups.Cgroup
105104
}

runtime/v2/runc/service_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
4242
}
4343

4444
if stdin != "" {
45-
in, err := fifo.OpenFifo(ctx, stdin, syscall.O_RDONLY, 0)
45+
in, err := fifo.OpenFifo(ctx, stdin, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
4646
if err != nil {
4747
return nil, err
4848
}

0 commit comments

Comments
 (0)