瀏覽代碼

fix ffmpeg fallback decoder pipe deadlock

Prevent the fallback FFmpeg decoder from deadlocking on longer-running streams.

The decoder previously drained stderr with io.ReadAll() before reading PCM from stdout. Once FFmpeg filled the stdout pipe buffer, the process blocked on further stdout writes, never closed stderr, and io.ReadAll(stderr) never returned. That stalled the decoder before readPCM() could even start.

Drain stderr concurrently in its own goroutine so stdin, stdout, and stderr can all make progress in parallel. This matches the expected pipe handling model for long-running FFmpeg processes and keeps the fallback decoder usable for real streams.
main
Jan 1 月之前
父節點
當前提交
da68cd965d
共有 1 個文件被更改,包括 10 次插入1 次删除
  1. +10
    -1
      internal/ingest/decoder/fallback/ffmpeg.go

+ 10
- 1
internal/ingest/decoder/fallback/ffmpeg.go 查看文件

@@ -81,7 +81,16 @@ func (d *FFmpegDecoder) DecodeStream(ctx context.Context, r io.Reader, meta deco
}
}()

stderrData, _ := io.ReadAll(stderr)
// DEADLOCK FIX: stderr and stdout must be drained concurrently.
// Reading stderr synchronously before readPCM means ffmpeg blocks when
// stdout's pipe buffer fills (typically 64KB), which prevents it from
// closing stderr, which prevents ReadAll from returning — deadlock.
var stderrData []byte
wg.Add(1)
go func() {
defer wg.Done()
stderrData, _ = io.ReadAll(stderr)
}()
readErr := d.readPCM(ctx, stdout, sampleRate, channels, meta.SourceID, emit)
waitErr := cmd.Wait()
wg.Wait()


Loading…
取消
儲存