Repository: reef Updated Branches: refs/heads/master 848cf9298 -> a81e8acce
[REEF-973] Task exception status does not get set if Dispose throws Exception This addressed the issue by * Using try-catch-finally pattern. JIRA: [REEF-973](https://issues.apache.org/jira/browse/REEF-973) This closes #656 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/a81e8acc Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/a81e8acc Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/a81e8acc Branch: refs/heads/master Commit: a81e8acce31fa44472e8ebc08849e1d6814cae3a Parents: 848cf92 Author: Andrew Chung <[email protected]> Authored: Wed Nov 18 14:16:33 2015 -0800 Committer: Julia Wang <[email protected]> Committed: Wed Dec 2 10:10:07 2015 -0800 ---------------------------------------------------------------------- .../Runtime/Evaluator/Task/TaskRuntime.cs | 29 ++++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/a81e8acc/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs index f12dcd6..b695e95 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs @@ -133,25 +133,11 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Task var e = new InvalidOperationException("TaskRuntime not in Running state, instead it is in state " + _currentStatus.State); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } - byte[] result; + byte[] taskMemento = _memento.IsPresent() ? _memento.Value : null; - System.Threading.Tasks.Task<byte[]> runTask = new System.Threading.Tasks.Task<byte[]>(() => RunTask(taskMemento)); - try - { - runTask.Start(); - runTask.Wait(); - } - catch (Exception e) - { - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.CaughtAndThrow(e, Level.Error, "Exception thrown during task running.", LOGGER); - } - result = runTask.Result; + var result = RunTask(taskMemento); LOGGER.Log(Level.Info, "Task Call Finished"); - if (_task != null) - { - _task.Dispose(); - } _currentStatus.SetResult(result); if (result != null && result.Length > 0) { @@ -160,13 +146,14 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Task } catch (Exception e) { - if (_task != null) - { - _task.Dispose(); - } - LOGGER.Log(Level.Warning, string.Format(CultureInfo.InvariantCulture, "Task failed caused by exception [{0}]", e)); + LOGGER.Log(Level.Warning, + string.Format(CultureInfo.InvariantCulture, "Task failed caused by exception [{0}]", e)); _currentStatus.SetException(e); } + finally + { + _task.Dispose(); + } } public TaskState GetTaskState()
