Merge pull request #3809 from warwickmm/dispose_backends

Dispose backends after upload operations
This commit is contained in:
Rune Henriksen
2019-07-09 21:09:22 +02:00
committed by GitHub
2 changed files with 19 additions and 4 deletions
@@ -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());
}
});
}
@@ -443,7 +453,7 @@ namespace Duplicati.Library.Main.Operation.Backup
}
}
private class Worker
private class Worker : IDisposable
{
public Task Task;
public IBackend Backend;
@@ -453,6 +463,12 @@ namespace Duplicati.Library.Main.Operation.Backup
Backend = backend;
Task = Task.FromResult(true);
}
public void Dispose()
{
this.Task?.Dispose();
this.Backend?.Dispose();
}
}
}
}
@@ -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))
{