GetAudio: avoid leaking goroutine on cancellation
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-02-05 07:45:03 +01:00
parent 54e9bc0d2c
commit a8ba36a0e1
1 changed files with 4 additions and 15 deletions

View File

@ -173,25 +173,14 @@ func (s *audioGetterState) getAudio(ctx context.Context, r io.ReadCloser, mediaS
})
g.Go(func() error {
defer func() { _ = r.Close() }()
defer func() { _ = uploadWriter.Close() }()
defer func() { _ = ffmpegWriter.Close() }()
if _, err := io.Copy(mw, streamWithProgress); err != nil {
return fmt.Errorf("error copying: %v", err)
}
// ignoring the following Close errors should be ok, as the Copy has
// already completed successfully.
if err := ffmpegWriter.Close(); err != nil {
s.logger.With("err", err).Warn("getAudio: unable to close ffmpegWriter")
}
if err := uploadWriter.Close(); err != nil {
s.logger.With("err", err).Warn("getAudio: unable to close pipeWriter")
}
if err := r.Close(); err != nil {
s.logger.With("err", err).Warn("getAudio: unable to close stream")
}
return nil
})