From 8e9e15164b588523d0fbc8efb4648f6d1eafec42 Mon Sep 17 00:00:00 2001 From: Christoph Ostarek Date: Mon, 18 Dec 2023 14:01:24 +0100 Subject: [PATCH] logread: do not close socket too early only close socket once reading is finished Signed-off-by: Christoph Ostarek --- pkg/memlogd/cmd/logread/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/memlogd/cmd/logread/main.go b/pkg/memlogd/cmd/logread/main.go index 6f6b5a85b4..c533c50d4d 100644 --- a/pkg/memlogd/cmd/logread/main.go +++ b/pkg/memlogd/cmd/logread/main.go @@ -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 { @@ -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)