Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Skovhede <kenneth@hexad.dk>2014-08-11 22:59:00 +0400
committerKenneth Skovhede <kenneth@hexad.dk>2014-08-11 22:59:00 +0400
commit01c64e1b9d04c27ff9305e6ba6089d1ee6b88b42 (patch)
treee452a5094bd9e0318365668960d15a7c76eb4896
parent96462d786668599b7caab23e80d49aafdbf0a092 (diff)
Improved the worker thread to prevent crashes of the worker on Windows.v2.0.0.56-2.0_preview_2014-08-11
-rw-r--r--Duplicati/Library/Utility/WorkerThread.cs34
-rw-r--r--Duplicati/Server/Program.cs7
-rw-r--r--Duplicati/Server/Scheduler.cs6
3 files changed, 32 insertions, 15 deletions
diff --git a/Duplicati/Library/Utility/WorkerThread.cs b/Duplicati/Library/Utility/WorkerThread.cs
index 7a74c9c23..383c999de 100644
--- a/Duplicati/Library/Utility/WorkerThread.cs
+++ b/Duplicati/Library/Utility/WorkerThread.cs
@@ -73,15 +73,19 @@ namespace Duplicati.Library.Utility
/// <summary>
/// Event that occurs when a new operation is being processed
/// </summary>
- public event EventHandler StartingWork;
+ public event Action<WorkerThread<Tx>, Tx> StartingWork;
/// <summary>
/// Event that occurs when an operation has completed
/// </summary>
- public event EventHandler CompletedWork;
+ public event Action<WorkerThread<Tx>, Tx> CompletedWork;
+ /// <summary>
+ /// Event that occurs when an error is detected
+ /// </summary>
+ public event Action<WorkerThread<Tx>, Tx, Exception> OnError;
/// <summary>
/// An evnet that occurs when a new task is added to the queue or an existing one is removed
/// </summary>
- public event EventHandler WorkQueueChanged;
+ public event Action<WorkerThread<Tx>> WorkQueueChanged;
/// <summary>
/// The internal state
@@ -155,7 +159,7 @@ namespace Duplicati.Library.Utility
}
if (WorkQueueChanged != null)
- WorkQueueChanged(this, null);
+ WorkQueueChanged(this);
}
/// <summary>
@@ -178,7 +182,7 @@ namespace Duplicati.Library.Utility
}
if (WorkQueueChanged != null)
- WorkQueueChanged(this, null);
+ WorkQueueChanged(this);
}
/// <summary>
@@ -277,24 +281,36 @@ namespace Duplicati.Library.Utility
continue;
if (StartingWork != null)
- StartingWork(this, null);
+ StartingWork(this, m_currentTask);
try
{
m_active = true;
m_delegate(m_currentTask);
}
- catch (System.Threading.ThreadAbortException)
+ catch (Exception ex)
{
- System.Threading.Thread.ResetAbort();
+ System.Threading.Thread.ResetAbort();
+ if (OnError != null)
+ try { OnError(this, m_currentTask, ex); }
+ catch { }
}
finally
{
+ System.Threading.Thread.ResetAbort();
m_active = false;
}
+ var task = m_currentTask;
+ m_currentTask = null;
+
if (CompletedWork != null)
- CompletedWork(this, null);
+ try { CompletedWork(this, task); }
+ catch (Exception ex)
+ {
+ try { OnError(this, task, ex); }
+ catch { }
+ }
}
}
diff --git a/Duplicati/Server/Program.cs b/Duplicati/Server/Program.cs
index f55bd7cbb..067d1da13 100644
--- a/Duplicati/Server/Program.cs
+++ b/Duplicati/Server/Program.cs
@@ -408,10 +408,11 @@ namespace Duplicati.Server
}, LiveControl.State == LiveControls.LiveControlState.Paused);
Program.Scheduler = new Scheduler(WorkThread);
- Program.WorkThread.StartingWork += new EventHandler(SignalNewEvent);
- Program.WorkThread.CompletedWork += new EventHandler(SignalNewEvent);
- Program.WorkThread.WorkQueueChanged += new EventHandler(SignalNewEvent);
+ Program.WorkThread.StartingWork += (worker, task) => { SignalNewEvent(null, null); };
+ Program.WorkThread.CompletedWork += (worker, task) => { SignalNewEvent(null, null); };
+ Program.WorkThread.WorkQueueChanged += (worker) => { SignalNewEvent(null, null); };
Program.Scheduler.NewSchedule += new EventHandler(SignalNewEvent);
+ Program.WorkThread.OnError += (worker, task, exception) => { Program.DataConnection.LogError(task == null ? null : task.BackupID, "Error in worker", exception); };
Program.WebServer = new WebServer.Server(commandlineOptions);
diff --git a/Duplicati/Server/Scheduler.cs b/Duplicati/Server/Scheduler.cs
index 70becc966..d97a97179 100644
--- a/Duplicati/Server/Scheduler.cs
+++ b/Duplicati/Server/Scheduler.cs
@@ -169,13 +169,13 @@ namespace Duplicati.Server
return res;
}
- private void OnCompleted(object sender, EventArgs e)
+ private void OnCompleted(WorkerThread<Runner.IRunnerData> worker, Runner.IRunnerData task)
{
Tuple<ISchedule, DateTime, DateTime> t = null;
lock(m_lock)
{
- if (m_updateTasks.TryGetValue(m_worker.CurrentTask, out t))
- m_updateTasks.Remove(m_worker.CurrentTask);
+ if (task != null && m_updateTasks.TryGetValue(task, out t))
+ m_updateTasks.Remove(task);
}
if (t != null)