Commit e23320b7 authored by Dominik Charousset's avatar Dominik Charousset

Fix exception and timeout handling

Correctly turn exceptions into errors in event-based actors and fix timeout
handling in brokers.
parent 37b39987
...@@ -86,6 +86,8 @@ enum class sec : uint8_t { ...@@ -86,6 +86,8 @@ enum class sec : uint8_t {
unknown_type, unknown_type,
/// Serialization of actors failed because no proxy registry is available. /// Serialization of actors failed because no proxy registry is available.
no_proxy_registry, no_proxy_registry,
/// An exception was thrown during message handling.
runtime_error,
/// A function view was called without assigning an actor first. /// A function view was called without assigning an actor first.
bad_function_call bad_function_call
}; };
......
...@@ -72,6 +72,26 @@ void scheduled_actor::default_exit_handler(scheduled_actor* ptr, exit_msg& x) { ...@@ -72,6 +72,26 @@ void scheduled_actor::default_exit_handler(scheduled_actor* ptr, exit_msg& x) {
default_error_handler(ptr, x.reason); default_error_handler(ptr, x.reason);
} }
# ifndef CAF_NO_EXCEPTIONS
error scheduled_actor::default_exception_handler(pointer ptr,
std::exception_ptr& x) {
CAF_ASSERT(x != nullptr);
try {
std::rethrow_exception(x);
} catch (const std::exception& e) {
aout(ptr) << "*** unhandled exception: [id: " << ptr->id()
<< ", name: " << ptr->name() << ", exception typeid: "
<< typeid(e).name() << "]: " << e.what()
<< std::endl;
} catch (...) {
aout(ptr) << "*** unhandled exception: [id: " << ptr->id()
<< ", name: " << ptr->name() << "]: unknown exception"
<< std::endl;
}
return sec::runtime_error;
}
# endif // CAF_NO_EXCEPTIONS
// -- constructors and destructors --------------------------------------------- // -- constructors and destructors ---------------------------------------------
scheduled_actor::scheduled_actor(actor_config& cfg) scheduled_actor::scheduled_actor(actor_config& cfg)
...@@ -81,7 +101,11 @@ scheduled_actor::scheduled_actor(actor_config& cfg) ...@@ -81,7 +101,11 @@ scheduled_actor::scheduled_actor(actor_config& cfg)
error_handler_(default_error_handler), error_handler_(default_error_handler),
down_handler_(default_down_handler), down_handler_(default_down_handler),
exit_handler_(default_exit_handler), exit_handler_(default_exit_handler),
private_thread_(nullptr) { private_thread_(nullptr)
# ifndef CAF_NO_EXCEPTIONS
, exception_handler_(default_exception_handler)
# endif // CAF_NO_EXCEPTIONS
{
// nop // nop
} }
...@@ -513,7 +537,10 @@ auto scheduled_actor::activate(execution_unit* ctx, mailbox_element& x) ...@@ -513,7 +537,10 @@ auto scheduled_actor::activate(execution_unit* ctx, mailbox_element& x)
CAF_LOG_TRACE(CAF_ARG(x)); CAF_LOG_TRACE(CAF_ARG(x));
if (!activate(ctx)) if (!activate(ctx))
return activation_result::terminated; return activation_result::terminated;
return reactivate(x); auto res = reactivate(x);
if (res == activation_result::success && !bhvr_stack_.empty())
request_timeout(bhvr_stack_.back().timeout());
return res;
} }
auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result { auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
......
...@@ -52,6 +52,7 @@ const char* sec_strings[] = { ...@@ -52,6 +52,7 @@ const char* sec_strings[] = {
"no_context", "no_context",
"unknown_type", "unknown_type",
"no_proxy_registry", "no_proxy_registry",
"runtime_error",
"bad_function_call" "bad_function_call"
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment