Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Properly kill the context on HostFailureException
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 28 Aug 2018 23:59:17 +0000 (01:59 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 29 Aug 2018 09:53:41 +0000 (11:53 +0200)
Before, simix was kinda thinking that the actor was dead, but the
context was still running, leading to a Holy Big Mess!

src/kernel/context/Context.cpp
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextThread.hpp
src/kernel/context/ContextUnix.cpp

index ca6e447..60ad851 100644 (file)
@@ -8,6 +8,8 @@
 #include "src/kernel/context/Context.hpp"
 #include "src/simix/smx_private.hpp"
 
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
+
 /**
  * @brief creates a new context for a user level process
  * @param code a main function
@@ -80,8 +82,7 @@ void Context::stop()
   this->process_->suspended_ = 0;
 
   this->iwannadie = false;
-  if (not this->process_->finished_) // It seems that we sometimes try to destroy an actor twice
-    simgrid::simix::simcall([this] { SIMIX_process_cleanup(this->process_); });
+  simgrid::simix::simcall([this] { SIMIX_process_cleanup(this->process_); });
   this->iwannadie = true;
 }
 
index a0fb566..e5b557f 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "ContextBoost.hpp"
 #include "context_private.hpp"
+#include "simgrid/Exception.hpp"
 #include "src/simix/smx_private.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
@@ -113,10 +114,12 @@ void BoostContext::wrapper(BoostContext::arg_type arg)
 #endif
   try {
     (*context)();
-    context->Context::stop();
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
+  } catch (simgrid::HostFailureException const&) {
+    XBT_DEBUG("Caught an HostFailureException");
   }
+  context->Context::stop();
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }
index f76faf6..6c3e92a 100644 (file)
@@ -6,6 +6,7 @@
 #include "ContextRaw.hpp"
 #include "context_private.hpp"
 #include "mc/mc.h"
+#include "simgrid/Exception.hpp"
 #include "src/simix/smx_private.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
@@ -261,10 +262,13 @@ void RawContext::wrapper(void* arg)
   ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
   try {
     (*context)();
-    context->Context::stop();
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
+  } catch (simgrid::HostFailureException const&) {
+    XBT_DEBUG("Caught an HostFailureException");
   }
+  context->Context::stop();
+
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }
index d18e04c..5c2e86d 100644 (file)
@@ -3,16 +3,17 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <utility>
-#include <functional>
+#include "src/kernel/context/ContextThread.hpp"
 
+#include "simgrid/Exception.hpp"
 #include "src/internal_config.h" /* loads context system definitions */
 #include "src/simix/smx_private.hpp"
 #include "src/xbt_modinter.h" /* prototype of os thread module's init/exit in XBT */
 #include "xbt/function_types.h"
 #include "xbt/xbt_os_thread.h"
 
-#include "src/kernel/context/ContextThread.hpp"
+#include <functional>
+#include <utility>
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
@@ -120,7 +121,11 @@ void *ThreadContext::wrapper(void *param)
   } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
     xbt_assert(not context->is_maestro(), "I'm not supposed to be maestro here.");
+  } catch (simgrid::HostFailureException const&) {
+    XBT_DEBUG("Caught an HostFailureException");
   }
+  if (not context->is_maestro()) // really?
+    context->Context::stop();
 
   // Signal to the caller (normally the maestro) that we have finished:
   context->yield();
index 819e07c..a0b958e 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2009-2018. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -9,8 +8,9 @@
 #ifndef SIMGRID_SIMIX_THREAD_CONTEXT_HPP
 #define SIMGRID_SIMIX_THREAD_CONTEXT_HPP
 
-#include <simgrid/simix.hpp>
-
+#include "simgrid/simix.hpp"
+#include "src/kernel/context/Context.hpp"
+#include "xbt/xbt_os_thread.h"
 
 namespace simgrid {
 namespace kernel {
index 3e98fc7..d821c3c 100644 (file)
@@ -5,13 +5,15 @@
 
 /* \file UContext.cpp Context switching with ucontexts from System V        */
 
-#include "ContextUnix.hpp"
 #include "context_private.hpp"
 
 #include "mc/mc.h"
+#include "simgrid/Exception.hpp"
 #include "src/mc/mc_ignore.hpp"
 #include "src/simix/ActorImpl.hpp"
 
+#include "ContextUnix.hpp"
+
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 /** Many integers are needed to store a pointer
@@ -121,10 +123,12 @@ void UContext::smx_ctx_sysv_wrapper(int i1, int i2)
   ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
   try {
     (*context)();
-    context->Context::stop();
   } catch (simgrid::kernel::context::Context::StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
+  } catch (simgrid::HostFailureException const&) {
+    XBT_DEBUG("Caught an HostFailureException");
   }
+  context->Context::stop();
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
 }