mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-23 15:23:28 +00:00
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 <roesler.lucas@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
480f566819
commit
19abc9f7b9
@ -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
|
// 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
|
// error for as long as possible. If the cmd starts correctly, we are highly likely to
|
||||||
// succeed anyway
|
// succeed anyway
|
||||||
msgs := make(chan logs.Message, 100)
|
msgs := make(chan logs.Message)
|
||||||
go streamLogs(ctx, cmd, stdout, msgs)
|
go streamLogs(ctx, cmd, stdout, msgs)
|
||||||
go logErrOut(stderr)
|
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
|
// the loop is based on the Decoder example in the docs
|
||||||
// https://golang.org/pkg/encoding/json/#Decoder.Decode
|
// https://golang.org/pkg/encoding/json/#Decoder.Decode
|
||||||
func streamLogs(ctx context.Context, cmd *exec.Cmd, out io.ReadCloser, msgs chan logs.Message) {
|
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())
|
log.Println("starting journal stream using ", cmd.String())
|
||||||
|
|
||||||
// will ensure `out` is closed and all related resources cleaned up
|
// will ensure `out` is closed and all related resources cleaned up
|
||||||
|
Reference in New Issue
Block a user