-
Notifications
You must be signed in to change notification settings - Fork 749
fix: Ensure logs are not interrupted when disk is full #4603
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,14 @@ package jsonfile | |
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| "sync" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| timetypes "github.com/docker/docker/api/types/time" | ||
|
|
@@ -43,8 +45,26 @@ func Path(dataStore, ns, id string) string { | |
| return filepath.Join(dataStore, "containers", ns, id, id+"-json.log") | ||
| } | ||
|
|
||
| type discardWriter struct { | ||
| writer io.Writer | ||
| } | ||
|
|
||
| func (pw *discardWriter) Write(p []byte) (int, error) { | ||
| n, err := pw.writer.Write(p) | ||
| if err != nil && errors.Is(err, syscall.ENOSPC) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of ENOSPC, the write should be retried with sleep?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I afraid that if long term retry failed the container main process may hang, because pipe is full.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to retry forever
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how long do you think is appropriate? @AkihiroSuda
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If retry with some sleep I afraid that the consumer's consumption of container logs is slower than the producer's production of logs. |
||
| return len(p), nil | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you trying to do in this PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I make a mistack. @AkihiroSuda |
||
| } | ||
|
|
||
| return n, err | ||
| } | ||
|
|
||
| func newdiscardWriter(w io.Writer) *discardWriter { | ||
| return &discardWriter{writer: w} | ||
| } | ||
|
|
||
| func Encode(stdout <-chan string, stderr <-chan string, writer io.Writer) error { | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
| enc := json.NewEncoder(writer) | ||
| discardWriter := newdiscardWriter(writer) | ||
| enc := json.NewEncoder(discardWriter) | ||
| var encMu sync.Mutex | ||
| var wg sync.WaitGroup | ||
| wg.Add(2) | ||
|
|
||
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.