From f22c379a138fbf1f81be9ed4665c851f0d7b2382 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 28 Apr 2013 09:24:20 -0400 Subject: [PATCH] fixed directory watcher crash --- .../IO/DirectoryWatchers.cs | 64 +++++++------------ .../Library/LuceneSearchEngine.cs | 2 +- MediaBrowser.sln | 3 + Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 6 files changed, 33 insertions(+), 46 deletions(-) diff --git a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs index 150b28b4b1..d45952d6fd 100644 --- a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs @@ -36,12 +36,12 @@ namespace MediaBrowser.Server.Implementations.IO /// /// A dynamic list of paths that should be ignored. Added to during our own file sytem modifications. /// - private readonly ConcurrentDictionary _tempIgnoredPaths = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _tempIgnoredPaths = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); /// /// Any file name ending in any of these will be ignored by the watchers /// - private readonly List _alwaysIgnoreFiles = new List {"thumbs.db","small.jpg","albumart.jpg"}; + private readonly List _alwaysIgnoreFiles = new List { "thumbs.db", "small.jpg", "albumart.jpg" }; /// /// The timer lock @@ -97,7 +97,7 @@ namespace MediaBrowser.Server.Implementations.IO Logger = logManager.GetLogger("DirectoryWatchers"); ConfigurationManager = configurationManager; } - + /// /// Starts this instance. /// @@ -117,7 +117,7 @@ namespace MediaBrowser.Server.Implementations.IO } catch (IOException) { - return new string[] {}; + return new string[] { }; } }) @@ -265,49 +265,33 @@ namespace MediaBrowser.Server.Implementations.IO async void watcher_Error(object sender, ErrorEventArgs e) { var ex = e.GetException(); - var dw = (FileSystemWatcher) sender; + var dw = (FileSystemWatcher)sender; - Logger.ErrorException("Error in Directory watcher for: "+dw.Path, ex); + Logger.ErrorException("Error in Directory watcher for: " + dw.Path, ex); - if (ex.Message.Contains("network name is no longer available")) + //Network either dropped or, we are coming out of sleep and it hasn't reconnected yet - wait and retry + var retries = 0; + var success = false; + while (!success && retries < 10) { - //Network either dropped or, we are coming out of sleep and it hasn't reconnected yet - wait and retry - Logger.Warn("Network connection lost - will retry..."); - var retries = 0; - var success = false; - while (!success && retries < 10) - { - await Task.Delay(500).ConfigureAwait(false); + await Task.Delay(500).ConfigureAwait(false); - try - { - dw.EnableRaisingEvents = false; - dw.EnableRaisingEvents = true; - success = true; - } - catch (IOException) - { - Logger.Warn("Network still unavailable..."); - retries++; - } + try + { + dw.EnableRaisingEvents = false; + dw.EnableRaisingEvents = true; + success = true; } - if (!success) + catch (IOException) { - Logger.Warn("Unable to access network. Giving up."); - DisposeWatcher(dw); + Logger.Warn("Network still unavailable..."); + retries++; } - } - else + if (!success) { - if (!ex.Message.Contains("BIOS command limit")) - { - Logger.Info("Attempting to re-start watcher."); - - dw.EnableRaisingEvents = false; - dw.EnableRaisingEvents = true; - } - + Logger.Warn("Unable to access network. Giving up."); + DisposeWatcher(dw); } } @@ -455,7 +439,7 @@ namespace MediaBrowser.Server.Implementations.IO await Task.WhenAll(itemsToRefresh.Select(i => Task.Run(async () => { Logger.Info(i.Name + " (" + i.Path + ") will be refreshed."); - + try { await i.ChangedExternally().ConfigureAwait(false); @@ -531,7 +515,7 @@ namespace MediaBrowser.Server.Implementations.IO _updateTimer.Dispose(); _updateTimer = null; } - } + } _affectedPaths.Clear(); } diff --git a/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs b/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs index ea70f40796..e46ce0120c 100644 --- a/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs @@ -110,7 +110,7 @@ namespace MediaBrowser.Server.Implementations.Library var items = inputItems.Where(i => !(i is MusicArtist)).ToList(); - hints.AddRange(items.AsParallel().Select(item => + hints.AddRange(items.Select(item => { var index = GetIndex(item.Name, searchTerm, terms); diff --git a/MediaBrowser.sln b/MediaBrowser.sln index f9f5e94365..eb3251f741 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -173,4 +173,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection EndGlobal diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index cfcb93a521..fe05162b70 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.85 + 3.0.86 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index a5aba4b78e..569fb9fd41 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.85 + 3.0.86 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 85e6eae88b..045922c684 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.85 + 3.0.86 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +