From f954cf8bea9c6766e32a0d9cd0d7df5640344957 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sat, 6 Jul 2019 12:45:48 -0700 Subject: [PATCH 1/4] Remove unused variable. --- Duplicati/Library/Main/Operation/BackupHandler.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Duplicati/Library/Main/Operation/BackupHandler.cs b/Duplicati/Library/Main/Operation/BackupHandler.cs index 466f09d44..030189790 100644 --- a/Duplicati/Library/Main/Operation/BackupHandler.cs +++ b/Duplicati/Library/Main/Operation/BackupHandler.cs @@ -400,7 +400,6 @@ namespace Duplicati.Library.Main.Operation using(var backendManager = new BackendManager(m_backendurl, m_options, m_result.BackendWriter, m_database)) using(var filesetvolume = new FilesetVolumeWriter(m_options, m_database.OperationTimestamp)) using(var stats = new Backup.BackupStatsCollector(m_result)) - using(var bk = new Common.BackendHandler(m_options, m_backendurl, db, stats, m_result.TaskReader)) // Keep a reference to these channels to avoid shutdown using(var uploadtarget = ChannelManager.GetChannel(Backup.Channels.BackendRequest.ForWrite)) { From bfa3c120e592782608860b6757b614c9ac64acf9 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sat, 6 Jul 2019 12:50:37 -0700 Subject: [PATCH 2/4] Make Worker implement IDisposable. This will allow the underlying Task and Backend to be disposed. --- .../Library/Main/Operation/Backup/BackendUploader.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs index 97180f647..5c26539a4 100644 --- a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs +++ b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs @@ -443,7 +443,7 @@ namespace Duplicati.Library.Main.Operation.Backup } } - private class Worker + private class Worker : IDisposable { public Task Task; public IBackend Backend; @@ -453,6 +453,12 @@ namespace Duplicati.Library.Main.Operation.Backup Backend = backend; Task = Task.FromResult(true); } + + public void Dispose() + { + this.Task?.Dispose(); + this.Backend?.Dispose(); + } } } } From c1497929738eebf25b044bf8fefcdaac33f6c900 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sat, 6 Jul 2019 13:34:14 -0700 Subject: [PATCH 3/4] Dispose Backends after upload operations. This addresses issue #3808. --- .../Main/Operation/Backup/BackendUploader.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs index 5c26539a4..2925aa141 100644 --- a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs +++ b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs @@ -181,7 +181,9 @@ namespace Duplicati.Library.Main.Operation.Backup ExceptionDispatchInfo.Capture(finishedTask.Exception).Throw(); } - workers.RemoveAll(w => w.Task == finishedTask); + Worker finishedWorker = workers.Single(w => w.Task == finishedTask); + workers.Remove(finishedWorker); + finishedWorker.Dispose(); } flush.SetFlushed(lastSize); @@ -212,7 +214,14 @@ namespace Duplicati.Library.Main.Operation.Backup { await Task.WhenAll(workers.Select(w => w.Task)); } - catch { /* As we are cancelling all threads we do not need to alert the user to any of these exceptions */ } + catch + { + /* As we are cancelling all threads we do not need to alert the user to any of these exceptions */ + } + finally + { + workers.ForEach(w => w.Dispose()); + } throw; } @@ -224,6 +233,7 @@ namespace Duplicati.Library.Main.Operation.Backup finally { m_stats.SetBlocking(false); + workers.ForEach(w => w.Dispose()); } }); } From 7fd815b56e59308f3cdddeb50c61a39f35b38e35 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sat, 6 Jul 2019 15:34:46 -0700 Subject: [PATCH 4/4] Simplify comment. --- Duplicati/Library/Main/Operation/Backup/BackendUploader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs index 2925aa141..65ca193b2 100644 --- a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs +++ b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs @@ -216,7 +216,7 @@ namespace Duplicati.Library.Main.Operation.Backup } catch { - /* As we are cancelling all threads we do not need to alert the user to any of these exceptions */ + // As we are cancelling all threads we do not need to alert the user to any of these exceptions. } finally {