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: copy data before put it into ringbuf #1471

Merged
merged 1 commit into from
Jun 11, 2018
Merged
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
16 changes: 14 additions & 2 deletions daemon/containerio/container_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,28 @@ func (cio *ContainerIO) Write(data []byte) (int, error) {
return len(data), nil
}

// FIXME(fuwei): In case that the data slice is reused by the writer,
// we should copy the data before we push it into the ringbuffer.
// The previous data shares the same address with the coming data.
// If we don't copy the data and the previous data isn't consumed by
// ringbuf pop action, the incoming data will override the previous data
// in the ringbuf.
//
// However, copy data maybe impact the performance. We need to reconsider
// other better way to handle the IO.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, AWY, we need a better way to handle IO later !

copyData := make([]byte, len(data))
copy(copyData, data)

switch cio.typ {
case stdout:
for _, b := range cio.backends {
if cover := b.outRing.Push(data); cover {
if cover := b.outRing.Push(copyData); cover {
logrus.Warnf("cover data, backend: %s, id: %s", b.backend.Name(), cio.id)
}
}
case stderr:
for _, b := range cio.backends {
if cover := b.errRing.Push(data); cover {
if cover := b.errRing.Push(copyData); cover {
logrus.Warnf("cover data, backend: %s, id: %s", b.backend.Name(), cio.id)
}
}
Expand Down