From c652db8731e6705c5a11adeb9a80a22c4b2216b7 Mon Sep 17 00:00:00 2001 From: ryannewington Date: Mon, 30 May 2016 08:50:22 +1000 Subject: [PATCH] Fixes an issue where partial results from AD can build up causing high memory usage until GC runs Fixes an issue where search results are not released --- src/Lithnet.Miiserver.AutoSync.Setup/Product.wxs | 2 +- src/Lithnet.Miiserver.AutoSync/MAExecutor.cs | 12 ++++++++---- src/Lithnet.Miiserver.AutoSync/Settings.cs | 2 +- .../Triggers/ActiveDirectoryChangeTrigger.cs | 14 ++++++++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Lithnet.Miiserver.AutoSync.Setup/Product.wxs b/src/Lithnet.Miiserver.AutoSync.Setup/Product.wxs index 0da966d..fddacfc 100644 --- a/src/Lithnet.Miiserver.AutoSync.Setup/Product.wxs +++ b/src/Lithnet.Miiserver.AutoSync.Setup/Product.wxs @@ -4,7 +4,7 @@ diff --git a/src/Lithnet.Miiserver.AutoSync/MAExecutor.cs b/src/Lithnet.Miiserver.AutoSync/MAExecutor.cs index 87e2282..43fae26 100644 --- a/src/Lithnet.Miiserver.AutoSync/MAExecutor.cs +++ b/src/Lithnet.Miiserver.AutoSync/MAExecutor.cs @@ -269,8 +269,10 @@ private void Execute(ExecutionParameters e) Logger.WriteLine("{0}: {1} returned {2}", this.ma.Name, e.RunProfileName, ex.Result); } - RunDetails r = this.ma.GetLastRun(); - this.PerformPostRunActions(r); + using (RunDetails r = this.ma.GetLastRun()) + { + this.PerformPostRunActions(r); + } } catch (OperationCanceledException) { @@ -337,8 +339,10 @@ private void WaitOnUnmanagedRun() if (!this.token.IsCancellationRequested) { - RunDetails ur = this.ma.GetLastRun(); - this.PerformPostRunActions(ur); + using (RunDetails ur = this.ma.GetLastRun()) + { + this.PerformPostRunActions(ur); + } } } finally diff --git a/src/Lithnet.Miiserver.AutoSync/Settings.cs b/src/Lithnet.Miiserver.AutoSync/Settings.cs index c276c27..500854b 100644 --- a/src/Lithnet.Miiserver.AutoSync/Settings.cs +++ b/src/Lithnet.Miiserver.AutoSync/Settings.cs @@ -60,7 +60,7 @@ public static int MailMaxErrorItems int value; - return int.TryParse(s, out value) ? value : 0; + return int.TryParse(s, out value) ? value : 10; } } diff --git a/src/Lithnet.Miiserver.AutoSync/Triggers/ActiveDirectoryChangeTrigger.cs b/src/Lithnet.Miiserver.AutoSync/Triggers/ActiveDirectoryChangeTrigger.cs index 93a7449..9d5867f 100644 --- a/src/Lithnet.Miiserver.AutoSync/Triggers/ActiveDirectoryChangeTrigger.cs +++ b/src/Lithnet.Miiserver.AutoSync/Triggers/ActiveDirectoryChangeTrigger.cs @@ -84,6 +84,8 @@ private void SetupListener() private void Notify(IAsyncResult result) { + PartialResultsCollection col; + try { if (this.stopped) @@ -91,9 +93,9 @@ private void Notify(IAsyncResult result) this.connection.EndSendRequest(result); return; } - - PartialResultsCollection col = this.connection.GetPartialResults(result); - + + col = this.connection.GetPartialResults(result); + if (this.hasChanges) { return; @@ -154,7 +156,7 @@ private void Notify(IAsyncResult result) continue; } } - + Logger.WriteLine("AD change: {0}", r.DistinguishedName); Logger.WriteLine("LL: {0}", LogLevel.Debug, date1.ToLocalTime()); Logger.WriteLine("TS: {0}", LogLevel.Debug, date2.ToLocalTime()); @@ -175,6 +177,10 @@ private void Notify(IAsyncResult result) throw; } } + finally + { + col = null; + } } public void Start()