Skip to content

Commit b27f7da

Browse files
committed
task: don't close() io before cancel()
The contract for `cio/io.go/IO` states that a call to `Close()` will always be preceded by a call to `Cancel()` - https://github.com/containerd/containerd/blob/f3a07934b49bf142925a5913e3e19f3528eda0d2/cio/io.go#L59 which isn't being held up here. Furthermore, the call to `Close()` here makes the subsequent `Wait()` moot, and causes issues to consumers (see: moby/moby#45689) It seems from https://github.com/containerd/containerd/blob/f3a07934b49bf142925a5913e3e19f3528eda0d2/task.go#L338 that the `Close()` should be called there, the call removed in this commit is unnecessary/erroneous. We leave the `Close()` call on Windows only since this was introduced in #5974 to address #5621. Signed-off-by: Laura Brehm <[email protected]> (cherry picked from commit 34a93a0) Signed-off-by: Laura Brehm <[email protected]>
1 parent 7902825 commit b27f7da

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

task.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,16 @@ func (t *task) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStat
325325
return nil, fmt.Errorf("task must be stopped before deletion: %s: %w", status.Status, errdefs.ErrFailedPrecondition)
326326
}
327327
if t.io != nil {
328-
t.io.Close()
328+
// io.Wait locks for restored tasks on Windows unless we call
329+
// io.Close first (https://github.com/containerd/containerd/issues/5621)
330+
// in other cases, preserve the contract and let IO finish before closing
331+
if t.client.runtime == fmt.Sprintf("%s.%s", plugin.RuntimePlugin, "windows") {
332+
t.io.Close()
333+
}
334+
// io.Cancel is used to cancel the io goroutine while it is in
335+
// fifo-opening state. It does not stop the pipes since these
336+
// should be closed on the shim's side, otherwise we might lose
337+
// data from the container!
329338
t.io.Cancel()
330339
t.io.Wait()
331340
}

0 commit comments

Comments
 (0)