From d5f080fefbac63736a8c01acebe08e6617c5c486 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 15 Mar 2019 17:56:19 +0100 Subject: [PATCH] Check before flushing ffmpeg log The stream could have been diposed while writing. --- MediaBrowser.Controller/MediaEncoding/JobLogger.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs index 46593fb2f..2755bf581 100644 --- a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs +++ b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs @@ -10,7 +10,7 @@ namespace MediaBrowser.Controller.MediaEncoding { public class JobLogger { - private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + private static readonly CultureInfo _usCulture = CultureInfo.ReadOnly(new CultureInfo("en-US")); private readonly ILogger _logger; public JobLogger(ILogger logger) @@ -24,7 +24,7 @@ namespace MediaBrowser.Controller.MediaEncoding { using (var reader = new StreamReader(source)) { - while (!reader.EndOfStream) + while (!reader.EndOfStream && reader.BaseStream.CanRead) { var line = await reader.ReadLineAsync().ConfigureAwait(false); @@ -39,6 +39,13 @@ namespace MediaBrowser.Controller.MediaEncoding } await target.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); + + // Check again, the stream could have been closed + if (!target.CanWrite) + { + break; + } + await target.FlushAsync().ConfigureAwait(false); } }