-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[docker plugin] Refactor pipeline reader for data safety #14375
[docker plugin] Refactor pipeline reader for data safety #14375
Conversation
Removed a bunch of dependencies that are no longer needed with this PR, hence the impressive diff. |
if err != nil { | ||
return errors.Wrap(err, "error getting length frame") | ||
} | ||
fmt.Fprintf(os.Stderr, "Got header specifying length %d\n", lenFrame) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah, I completely forgot I put those in.
return nil, errors.Wrapf(err, "error opening logger fifo: %q", file) | ||
} | ||
|
||
return &PipeReader{fifoPipe: inputFile, byteOrder: binary.BigEndian, lenFrameBuf: make([]byte, 4), bodyBuf: nil, maxSize: 2e6}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider calling NewReaderFromReadCloser
if err != nil { | ||
return errors.Wrap(err, "error reading buffer") | ||
} | ||
return proto.Unmarshal(readBuf[:lenFrame], log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: given len(readBuf) == lenFrame
we don't need readBuf[:lenFrame]
.
* refactor pipeline reader for data safety
Thanks a ton to @urso for helping me understand what was actually going on here.
What is this?
This addresses an item mentioned in #13990 :
The issue is that the original reader,
Uint32DelimitedReader
, can improperly scroll through the buffer and leave it in an invalid state.A FIFO reader from docker is a stream, consisting of a length header and a body. This new reader takes a three-step approach when it comes to scrolling through the buffer:
length
bytes and continue.How do I test this?
On a host that has docker, run
mage build
andmage install
. After that, connect to a running container with a command like:docker run --log-driver=ossifrage/dockerlogbeat:0.0.1 --log-opt output.elasticsearch.hosts="172.18.0.2:9200" --log-opt output.elasticsearch.index="dockerbeat-test" -it debian:jessie /bin/bash