Skip to content

[20.10 backport] daemon/logger: read the length header correctly#43165

Merged
cpuguy83 merged 4 commits into
moby:20.10from
thaJeztah:20.10_backport_logs_fixes
Jan 27, 2022
Merged

[20.10 backport] daemon/logger: read the length header correctly#43165
cpuguy83 merged 4 commits into
moby:20.10from
thaJeztah:20.10_backport_logs_fixes

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

fixes #42125

Backport of:


Before this change, if Decode() couldn't read a log record fully,
the subsequent invocation of Decode() would read the record's non-header part
as a header and cause a huge heap allocation.

This change prevents such a case by having the intermediate buffer in
the decoder struct.

Fixes #42125.

- What I did

Changing decoder struct to fix #42125.

- How I did it

Changing decoder struct to keep read-but-unused bytes.

- How to verify it

Run docker logs -f $(docker run --rm -d --log-driver local alpine cat /dev/urandom) > /dev/null. It kills dockerd after a few minutes before the change.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

Havam

(from https://www.zooborns.com/zooborns/2021/05/two-very-different-babies-emerge-at-woodland-park-zoo.html)

Kazuyoshi Kato added 4 commits January 20, 2022 09:38
Before this change, if Decode() couldn't read a log record fully,
the subsequent invocation of Decode() would read the record's non-header part
as a header and cause a huge heap allocation.

This change prevents such a case by having the intermediate buffer in
the decoder struct.

Fixes moby#42125.

Signed-off-by: Kazuyoshi Kato <[email protected]>
(cherry picked from commit 48d387a)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Kazuyoshi Kato <[email protected]>
(cherry picked from commit f2e458e)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
followLogs() is getting really long (170+ lines) and complex.
The function has multiple inner functions that mutate its variables.

To refactor the function, this change introduces follow{} struct.
The inner functions are now defined as ordinal methods, which are
accessible from tests.

Signed-off-by: Kazuyoshi Kato <[email protected]>
(cherry picked from commit 7a10f5a)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Kazuyoshi Kato <[email protected]>
(cherry picked from commit c91e09b)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah

Copy link
Copy Markdown
Member Author

@cpuguy83 @samuelkarp ptal

@cpuguy83 cpuguy83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@wangw469

Copy link
Copy Markdown

I can't verify this issuse by runing

docker logs -f $(docker run --rm -d --log-driver local alpine cat /dev/urandom) > /dev/null

I can reproduce it by running (thanks to @aeriksson )

terminal 1

docker run --log-driver local -it --rm --name foo ubuntu sh -c "apt-get update && apt-get install -y nyancat && nyancat"

terminal 2

docker logs -f foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants