Pārlūkot izejas kodu

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 pirms 1 mēnesi
vecāks
revīzija
da68cd965d
1 mainītis faili ar 10 papildinājumiem un 1 dzēšanām
  1. +10
    -1
      internal/ingest/decoder/fallback/ffmpeg.go

+ 10
- 1
internal/ingest/decoder/fallback/ffmpeg.go Parādīt failu

@@ -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()


Notiek ielāde…
Atcelt
Saglabāt