From 6511401fa440894b9f254b873ab871fbbf2be429 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 25 Sep 2019 08:25:51 +0200 Subject: [PATCH] Fixed race condition between service and runtime, occurring when the runtime initiated a new session before the service was able to terminate the currently running one. --- .../SessionInitializationOperation.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs b/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs index ad223551..fb54b144 100644 --- a/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs +++ b/SafeExamBrowser.Service/Operations/SessionInitializationOperation.cs @@ -42,10 +42,16 @@ namespace SafeExamBrowser.Service.Operations public override OperationResult Revert() { var success = true; + var wasRunning = Context.IsRunning; - logger.Info("Finalizing current session..."); + logger.Info("Starting auto-restore mechanism..."); + Context.AutoRestoreMechanism.Start(); - if (Context.ServiceEvent != null && Context.IsRunning) + logger.Info("Clearing session data..."); + Context.Configuration = null; + Context.IsRunning = false; + + if (Context.ServiceEvent != null && wasRunning) { success = Context.ServiceEvent.Set(); @@ -59,13 +65,6 @@ namespace SafeExamBrowser.Service.Operations } } - logger.Info("Starting auto-restore mechanism..."); - Context.AutoRestoreMechanism.Start(); - - logger.Info("Clearing session data..."); - Context.Configuration = null; - Context.IsRunning = false; - return success ? OperationResult.Success : OperationResult.Failed; }