Skip to content
Open
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
22 changes: 21 additions & 1 deletion pkg/logging/jsonfile/jsonfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

In the case of ENOSPC, the write should be retried with sleep?

Copy link
Contributor Author

@ningmingxiao ningmingxiao Nov 17, 2025

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

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

No need to retry forever

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how long do you think is appropriate? @AkihiroSuda

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

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

What are you trying to do in this PR?
Doesn't seem correct to discard all syscall errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
enc := json.NewEncoder(writer)
discardWriter := newdiscardWriter(writer)
enc := json.NewEncoder(discardWriter)
var encMu sync.Mutex
var wg sync.WaitGroup
wg.Add(2)
Expand Down
Loading