Description
In https://github.com/containerd/containerd/blob/master/runtime/v1/linux/proc/io.go#L124 , the sameFile variable is shared if stdout and stderr are equal.
This causes a race where one goroutine may close the descriptor before the other has finished writing to it. The error is returned from io.CopyBuffer() and ignored, so this failure is silent. It can be confirmed by logging the error with log.G(ctx).WithError(err).Warn("error copying pipes").
Steps to reproduce the issue:
- Create a task with
cio.LogFile() as the cio.Creator https://github.com/containerd/containerd/blob/master/cio/io.go#L271-L272
- Have task output to both
stdout/stderr; I was using sh -xc "cat /file && md5sum file"
- Observe output logged to file.
- Repeat (in my environment, 5 is enough to get varying file sizes)
Describe the results you received:
Stdout/stderr are randomly truncated.
-rw-r--r-- 1 root root 469 Mar 20 13:26 /var/lib/thepwagner/containers/8295d165-d4d4-47ea-ba75-1c0ba854f8ba/log
-rw-r--r-- 1 root root 469 Mar 20 13:25 /var/lib/thepwagner/containers/b91158f8-58f7-4bca-927b-6e9d63afcde2/log
-rw-r--r-- 1 root root 469 Mar 20 13:25 /var/lib/thepwagner/containers/bd07790f-b24f-4442-a447-62bb6bf21ef5/log
-rw-r--r-- 1 root root 494 Mar 20 13:26 /var/lib/thepwagner/containers/ca55bd1b-ba5d-4f40-9a50-cb43366436f6/log
-rw-r--r-- 1 root root 469 Mar 20 13:25 /var/lib/thepwagner/containers/fd2168aa-77f0-403e-832e-058047738274/log
time="2019-03-20T13:26:08.232853828-07:00" level=warning msg="error copying pipes" error="write /var/lib/thepwagner/containers/8295d165-d4d4-47ea-ba75-1c0ba854f8ba/log: file already closed" runtime=io.containerd.runc.v1
Describe the results you expected:
Stdout/stderr are written in their entirety.
Output of containerd --version:
containerd github.com/containerd/containerd v1.2.5.m bb71b10fd8f58240ca47fbb579b9d1028eea7c84.m
Description
In https://github.com/containerd/containerd/blob/master/runtime/v1/linux/proc/io.go#L124 , the
sameFilevariable is shared ifstdoutandstderrare equal.This causes a race where one goroutine may close the descriptor before the other has finished writing to it. The error is returned from
io.CopyBuffer()and ignored, so this failure is silent. It can be confirmed by logging the error withlog.G(ctx).WithError(err).Warn("error copying pipes").Steps to reproduce the issue:
cio.LogFile()as thecio.Creatorhttps://github.com/containerd/containerd/blob/master/cio/io.go#L271-L272stdout/stderr; I was usingsh -xc "cat /file && md5sum file"Describe the results you received:
Stdout/stderr are randomly truncated.
Describe the results you expected:
Stdout/stderr are written in their entirety.
Output of
containerd --version: