Skip to content

Commit

Permalink
logread: do not close socket too early
Browse files Browse the repository at this point in the history
only close socket once reading is finished

Signed-off-by: Christoph Ostarek <[email protected]>
  • Loading branch information
christoph-zededa committed Dec 18, 2023
1 parent 3a04052 commit 8e9e151
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/memlogd/cmd/logread/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func StreamLogs(socketPath string, follow, dump bool) (<-chan LogEntry, error) {
if err != nil {
return nil, err
}
defer conn.Close()

var n int
switch {
Expand All @@ -90,6 +89,7 @@ func StreamLogs(socketPath string, follow, dump bool) (<-chan LogEntry, error) {
decoder = json.NewDecoder(conn)
)
for {
defer conn.Close()
if err := decoder.Decode(&entry); err != nil {
if errors.Is(err, net.ErrClosed) || errors.Is(err, io.EOF) {
close(c)
Expand Down

0 comments on commit 8e9e151

Please sign in to comment.