From: Martin Quinson Date: Wed, 29 Aug 2018 09:35:10 +0000 (+0200) Subject: Display a msg when contexts are killed by uncatched exceptions X-Git-Tag: v3_21~141 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/bd13415f2c334a0f2fe258010f37f507ee1ded37 Display a msg when contexts are killed by uncatched exceptions and when I want to really kill an actor (eg when its host is turned off), I launch an uncatchable kernel::Context::StopRequest instead of a catchable simgrid::HostFailureException (which will be used in case of remote exec and similar) Maybe there should be a config flag to decide if we want to kill the simulation when an actor fails. The current setting forces the user to add try/catch (simgrid::Exception) around their main functions. That's not a bad thing either, not sure. --- diff --git a/src/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index 674f02d050..ac073aba41 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -58,9 +58,14 @@ public: class StopRequest { /** @brief Exception launched to kill a process, in order to properly unwind its stack and release RAII stuff * - * Nope, Sonar, this should not inherit of std::exception. + * Nope, Sonar, this should not inherit of std::exception nor of simgrid::Exception. * Otherwise, users may accidentally catch it with a try {} catch (std::exception) */ + public: + StopRequest() = default; + StopRequest(std::string msg) : msg_(msg) { } + private: + std::string msg_; }; bool iwannadie; diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index e5b557f9ed..121fa2b9ae 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -116,8 +116,9 @@ void BoostContext::wrapper(BoostContext::arg_type arg) (*context)(); } catch (StopRequest const&) { XBT_DEBUG("Caught a StopRequest"); - } catch (simgrid::HostFailureException const&) { - XBT_DEBUG("Caught an HostFailureException"); + } catch (simgrid::Exception const& e) { + XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get()); + throw e; } context->Context::stop(); ASAN_ONLY(context->asan_stop_ = true); diff --git a/src/kernel/context/ContextRaw.cpp b/src/kernel/context/ContextRaw.cpp index 6c3e92af5e..2edbd1d402 100644 --- a/src/kernel/context/ContextRaw.cpp +++ b/src/kernel/context/ContextRaw.cpp @@ -264,8 +264,9 @@ void RawContext::wrapper(void* arg) (*context)(); } catch (StopRequest const&) { XBT_DEBUG("Caught a StopRequest"); - } catch (simgrid::HostFailureException const&) { - XBT_DEBUG("Caught an HostFailureException"); + } catch (simgrid::Exception const& e) { + XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get()); + throw e; } context->Context::stop(); diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index 5c2e86d262..92350b5552 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -116,16 +116,14 @@ void *ThreadContext::wrapper(void *param) try { (*context)(); - if (not context->is_maestro()) // really? - context->Context::stop(); } 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"); + } catch (simgrid::Exception const& e) { + XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get()); + throw e; } - if (not context->is_maestro()) // really? - context->Context::stop(); + context->Context::stop(); // Signal to the caller (normally the maestro) that we have finished: context->yield(); diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index d821c3c7eb..a861b24d42 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -125,8 +125,9 @@ void UContext::smx_ctx_sysv_wrapper(int i1, int i2) (*context)(); } catch (simgrid::kernel::context::Context::StopRequest const&) { XBT_DEBUG("Caught a StopRequest"); - } catch (simgrid::HostFailureException const&) { - XBT_DEBUG("Caught an HostFailureException"); + } catch (simgrid::Exception const& e) { + XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get()); + throw e; } context->Context::stop(); ASAN_ONLY(context->asan_stop_ = true); diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 8c9e22a3c5..a91c4c8274 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -499,8 +499,9 @@ void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer) { process->suspended_ = false; process->exception = nullptr; + // Forcefully kill the actor if its host is turned off. Not an HostFailureException because you should not survive that if (process->host_->is_off()) - process->throw_exception(std::make_exception_ptr(simgrid::HostFailureException(XBT_THROW_POINT, "Host failed"))); + process->throw_exception(std::make_exception_ptr(simgrid::kernel::context::Context::StopRequest("Host failed"))); /* destroy the blocking synchro if any */ if (process->waiting_synchro != nullptr) {