Skip to content

Commit 89876b5

Browse files
committed
fix: Ensure logs are not interrupted, even if the disk becomes full and later recovers.
Signed-off-by: ningmingxiao <[email protected]>
1 parent 2165e30 commit 89876b5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pkg/logging/jsonfile/jsonfile.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ package jsonfile
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"path/filepath"
2425
"strconv"
2526
"strings"
2627
"sync"
28+
"syscall"
2729
"time"
2830

2931
timetypes "github.com/docker/docker/api/types/time"
@@ -43,8 +45,26 @@ func Path(dataStore, ns, id string) string {
4345
return filepath.Join(dataStore, "containers", ns, id, id+"-json.log")
4446
}
4547

48+
type discardWriter struct {
49+
writer io.Writer
50+
}
51+
52+
func (pw *discardWriter) Write(p []byte) (int, error) {
53+
n, err := pw.writer.Write(p)
54+
if err != nil && errors.Is(err, syscall.ENOSPC) {
55+
return len(p), nil
56+
}
57+
58+
return n, err
59+
}
60+
61+
func newdiscardWriter(w io.Writer) *discardWriter {
62+
return &discardWriter{writer: w}
63+
}
64+
4665
func Encode(stdout <-chan string, stderr <-chan string, writer io.Writer) error {
47-
enc := json.NewEncoder(writer)
66+
discardWriter := newdiscardWriter(writer)
67+
enc := json.NewEncoder(discardWriter)
4868
var encMu sync.Mutex
4969
var wg sync.WaitGroup
5070
wg.Add(2)

0 commit comments

Comments
 (0)