-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
[regression in master] Corrupted logs #43647
Comments
@vvoland if you have a fix in mind; also don't hesitate to open a draft PR (having some code / approach to discuss never hurts :-) worst case scenario, the draft PR gets closed without merging) |
I'm leaning towards fixing it with a |
Sounds good to me. I will prepare a PR if you don't mind :-). |
Sure, go ahead @vvoland. I was thinking about changing the signature of |
How about leaving the WriteLogEntry as is and changing the logger.MarshalFunc to additionally take |
That could work, but would not be too friendly to the moby/daemon/logger/local/local.go Lines 95 to 131 in 262f574
|
One interesting observation is that interface {
Write([]byte) (int, error)
WriteString(string) (int, error)
WriteByte(byte) error
}
func (*LogFile) WriteLogEntry(time.Time, func(ThatWriterInterfaceAbove) error) error
func (*LogFile) WriteLogEntryBytes(time.Time, []byte) error Log drivers using |
That sounds good. On the other hand, given that there are only 2 drivers that use the WriteLogEntry, maybe we shouldn't overcomplicate the LogFile API :) |
Given that the root cause is a data race, it should be possible to write a unit test which would catch future regressions when run with |
Sure, will make a PR soon. |
@corhere included this test with the ones that led me to discovery of this regression. I closed the old PR and opened new for clarity: |
This should be resolved now. There's still an issue with specific Windows images, but that's not a bug in our code, but an issue with those images; see #43669 (comment) |
Description
Found it when writing tests for getting the container logs:
The logs are corrupted when capturing both stdout and stderr at the same time.
This isn't an issue with reading the logs, because the corruption is already visible in the json log file.
Example of corrupted json log file
First commit with the regression is ae5f664 (#43294)
The issue is that marshalFunc used in LogFile use a shared buffer. See:
With the mutex lock around WriteLogEntry got removed in the linked commit, the marshaller can be called for both stdout and stderr at the same time, which makes them write to the same buffer.
Allocating a buffer inside the marshaller call fixes the problem. But this is probably not a good idea because it would cause too many memory allocation? Maybe we should restore the critical section for the WriteLogEntry?
Steps to reproduce the issue:
docker logs -f $(docker run -d busybox sh -c 'echo stdout; echo stderr >&2')
Describe the results you received:
Randomly one of:
error from daemon in stream: Error grabbing logs: json: cannot unmarshal string into Go value of type jsonlog.JSONLog
Describe the results you expected:
Command should print
The text was updated successfully, but these errors were encountered: