From 19abc9f7b997acadecae3e7bca756bc8fb1d91d5 Mon Sep 17 00:00:00 2001 From: Lucas Roesler Date: Sat, 7 Mar 2020 11:22:59 +0100 Subject: [PATCH] Use an unbuffered log msg channel **What** - Instead of sleeping to ensure the msg channel is populated, use an unbuffered channel. This seems to work just as well in all the manual tests cases Signed-off-by: Lucas Roesler --- pkg/logs/requestor.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/logs/requestor.go b/pkg/logs/requestor.go index a209921..2df9c3b 100644 --- a/pkg/logs/requestor.go +++ b/pkg/logs/requestor.go @@ -49,7 +49,7 @@ func (r *requester) Query(ctx context.Context, req logs.Request) (<-chan logs.Me // call start and get the stdout prior to streaming so that we can return a meaningful // error for as long as possible. If the cmd starts correctly, we are highly likely to // succeed anyway - msgs := make(chan logs.Message, 100) + msgs := make(chan logs.Message) go streamLogs(ctx, cmd, stdout, msgs) go logErrOut(stderr) @@ -102,10 +102,6 @@ func buildCmd(ctx context.Context, req logs.Request) *exec.Cmd { // the loop is based on the Decoder example in the docs // https://golang.org/pkg/encoding/json/#Decoder.Decode func streamLogs(ctx context.Context, cmd *exec.Cmd, out io.ReadCloser, msgs chan logs.Message) { - // without this sleep the channel seems to get stuck. This results in either no log messages - // being read by the Handler _or_ the messages are read but only flushed when the request - // timesout - time.Sleep(time.Millisecond) log.Println("starting journal stream using ", cmd.String()) // will ensure `out` is closed and all related resources cleaned up