Let recorder worker close encoder stdin
This commit is contained in:
committed by
Brandon McGinty
parent
d07d7342da
commit
e309d22137
@@ -128,10 +128,9 @@ func (r *Recorder) Stop() error {
|
||||
return nil
|
||||
}
|
||||
r.once.Do(func() {
|
||||
// run owns stdin and closes it only after it has stopped writing.
|
||||
// Closing it here races writePCM and turns a normal stop into EPIPE.
|
||||
close(r.stop)
|
||||
if r.stdin != nil {
|
||||
r.stdin.Close()
|
||||
}
|
||||
})
|
||||
select {
|
||||
case <-r.done:
|
||||
|
||||
@@ -1,12 +1,35 @@
|
||||
package recording
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type trackingWriteCloser struct{ closed bool }
|
||||
|
||||
func (w *trackingWriteCloser) Write([]byte) (int, error) { return 0, nil }
|
||||
func (w *trackingWriteCloser) Close() error { w.closed = true; return nil }
|
||||
|
||||
var _ io.WriteCloser = (*trackingWriteCloser)(nil)
|
||||
|
||||
// Regression: Stop closed ffmpeg stdin while the worker could still write,
|
||||
// creating a spurious closed-pipe recording failure.
|
||||
func TestStopLeavesEncoderClosureToWorker(t *testing.T) {
|
||||
stdin := &trackingWriteCloser{}
|
||||
done := make(chan struct{})
|
||||
close(done)
|
||||
r := &Recorder{stdin: stdin, stop: make(chan struct{}), done: done}
|
||||
if err := r.Stop(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stdin.closed {
|
||||
t.Fatal("Stop closed stdin instead of the worker")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeFormat(t *testing.T) {
|
||||
tests := map[string]string{
|
||||
"": "flac",
|
||||
|
||||
Reference in New Issue
Block a user