From 96b3d37caf269789015900bd7f6fa24f17652848 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 24 Feb 2019 21:24:57 +0100 Subject: [PATCH 1/2] Check that ffmpeg log target isn't disposed before writing to it --- MediaBrowser.Controller/MediaEncoding/JobLogger.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs index b812a8ddc6..5cd6fd27a6 100644 --- a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs +++ b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs @@ -24,7 +24,8 @@ namespace MediaBrowser.Controller.MediaEncoding { using (var reader = new StreamReader(source)) { - while (!reader.EndOfStream) + // If ffmpeg process is closed, the state is disposed, so don't write to target in that case + while (!reader.EndOfStream && target.CanWrite) { var line = await reader.ReadLineAsync().ConfigureAwait(false); @@ -37,11 +38,6 @@ namespace MediaBrowser.Controller.MediaEncoding } } } - catch (ObjectDisposedException) - { - //TODO Investigate and properly fix. - // Don't spam the log. This doesn't seem to throw in windows, but sometimes under linux - } catch (Exception ex) { _logger.LogError(ex, "Error reading ffmpeg log"); From 547d0ecf584556019aa743687009a0f0d3a8f9dd Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 24 Feb 2019 22:04:30 +0100 Subject: [PATCH 2/2] Move the check further down --- MediaBrowser.Controller/MediaEncoding/JobLogger.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs index 5cd6fd27a6..46593fb2fc 100644 --- a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs +++ b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs @@ -24,8 +24,7 @@ namespace MediaBrowser.Controller.MediaEncoding { using (var reader = new StreamReader(source)) { - // If ffmpeg process is closed, the state is disposed, so don't write to target in that case - while (!reader.EndOfStream && target.CanWrite) + while (!reader.EndOfStream) { var line = await reader.ReadLineAsync().ConfigureAwait(false); @@ -33,6 +32,12 @@ namespace MediaBrowser.Controller.MediaEncoding var bytes = Encoding.UTF8.GetBytes(Environment.NewLine + line); + // If ffmpeg process is closed, the state is disposed, so don't write to target in that case + if (!target.CanWrite) + { + break; + } + await target.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); await target.FlushAsync().ConfigureAwait(false); }