diff --git a/codec/codecutil/lex.go b/codec/codecutil/lex.go index 61e71d4a..49d7344f 100644 --- a/codec/codecutil/lex.go +++ b/codec/codecutil/lex.go @@ -69,8 +69,11 @@ func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, d time.Duration) error { for { <-ticker.C off, err := src.Read(buf) - if err != nil { + // The only error that will stop the lexer is an EOF. + if err == io.EOF { return err + } else if err != nil { + continue } _, err = dst.Write(buf[:off]) if err != nil { diff --git a/device/alsa/alsa.go b/device/alsa/alsa.go index 73a56a83..bb1f1125 100644 --- a/device/alsa/alsa.go +++ b/device/alsa/alsa.go @@ -377,6 +377,10 @@ func (d *ALSA) input() { d.dev.Close() d.dev = nil } + err := d.buf.Close() + if err != nil { + d.l.Log(logger.Error, "unable to close pool buffer", "error", err) + } return } @@ -417,15 +421,15 @@ func (d *ALSA) Read(p []byte) (int, error) { _, err := d.buf.Next(rbNextTimeout) if err != nil { switch err { - case nil, io.EOF: - d.l.Log(logger.Debug, pkg+"EOF") - return 0, nil + case io.EOF: + d.l.Log(logger.Debug, pkg+"EOF from Next") + return 0, err case pool.ErrTimeout: d.l.Log(logger.Debug, pkg+"pool buffer timeout") - return 0, nil + return 0, err default: d.l.Log(logger.Error, pkg+"unexpected error from Next", "error", err.Error()) - return 0, nil + return 0, err } } @@ -434,12 +438,12 @@ func (d *ALSA) Read(p []byte) (int, error) { n, err := d.buf.Read(p) if err != nil { switch err { - case nil, io.EOF: - d.l.Log(logger.Debug, pkg+"EOF from Read, stopping") + case io.EOF: + d.l.Log(logger.Debug, pkg+"EOF from Read") return n, err default: d.l.Log(logger.Error, pkg+"unexpected error from Read", "error", err.Error()) - return n, nil + return n, err } } d.l.Log(logger.Debug, fmt.Sprintf("%v read %v bytes", pkg, n))