Unverified Commit bb22e7fe authored by Samir Halilčević's avatar Samir Halilčević Committed by GitHub

Send error if a request fails to deserialize

parent bd9c5704
...@@ -38,6 +38,8 @@ is based on [Keep a Changelog](https://keepachangelog.com). ...@@ -38,6 +38,8 @@ is based on [Keep a Changelog](https://keepachangelog.com).
- We renamed `caf::flow::item_publisher` to `caf::flow::multicaster` to better - We renamed `caf::flow::item_publisher` to `caf::flow::multicaster` to better
reflect its purpose and to avoid confusion with the new reflect its purpose and to avoid confusion with the new
`caf::async::publisher`. `caf::async::publisher`.
- When failing to deserialize a request, the sender will receive an error of
kind `sec::malformed_message`.
### Fixed ### Fixed
......
...@@ -22,8 +22,7 @@ sync_request_bouncer::sync_request_bouncer(error r) : rsn(std::move(r)) { ...@@ -22,8 +22,7 @@ sync_request_bouncer::sync_request_bouncer(error r) : rsn(std::move(r)) {
void sync_request_bouncer::operator()(const strong_actor_ptr& sender, void sync_request_bouncer::operator()(const strong_actor_ptr& sender,
const message_id& mid) const { const message_id& mid) const {
if (sender && mid.is_request()) if (sender && mid.is_request())
sender->enqueue(nullptr, mid.response_id(), sender->enqueue(nullptr, mid.response_id(), make_message(rsn),
make_message(make_error(sec::request_receiver_down)),
// TODO: this breaks out of the execution unit // TODO: this breaks out of the execution unit
nullptr); nullptr);
} }
......
...@@ -103,6 +103,8 @@ public: ...@@ -103,6 +103,8 @@ public:
auto t0 = telemetry::timer::clock_type::now(); auto t0 = telemetry::timer::clock_type::now();
if (!source.apply(msg)) { if (!source.apply(msg)) {
CAF_LOG_ERROR("failed to read message content:" << source.get_error()); CAF_LOG_ERROR("failed to read message content:" << source.get_error());
src->enqueue(nullptr, mid.response_id(),
make_message(make_error(sec::malformed_message)), nullptr);
return; return;
} }
telemetry::timer::observe(mm_metrics.deserialization_time, t0); telemetry::timer::observe(mm_metrics.deserialization_time, t0);
......
...@@ -5,8 +5,16 @@ using calculator ...@@ -5,8 +5,16 @@ using calculator
= caf::typed_actor<caf::result<int32_t>(caf::add_atom, int32_t, int32_t), = caf::typed_actor<caf::result<int32_t>(caf::add_atom, int32_t, int32_t),
caf::result<int32_t>(caf::sub_atom, int32_t, int32_t)>; caf::result<int32_t>(caf::sub_atom, int32_t, int32_t)>;
struct non_deserializable_t {
template <typename Inspector>
friend bool inspect(Inspector&, non_deserializable_t&) {
return !Inspector::is_loading;
}
};
CAF_BEGIN_TYPE_ID_BLOCK(io_test, caf::first_custom_type_id) CAF_BEGIN_TYPE_ID_BLOCK(io_test, caf::first_custom_type_id)
CAF_ADD_TYPE_ID(io_test, (calculator)) CAF_ADD_TYPE_ID(io_test, (calculator))
CAF_ADD_TYPE_ID(io_test, (non_deserializable_t))
CAF_END_TYPE_ID_BLOCK(io_test) CAF_END_TYPE_ID_BLOCK(io_test)
...@@ -101,4 +101,20 @@ CAF_TEST(remote_lookup allows registry lookups on other nodes) { ...@@ -101,4 +101,20 @@ CAF_TEST(remote_lookup allows registry lookups on other nodes) {
anon_send_exit(testee, exit_reason::user_shutdown); anon_send_exit(testee, exit_reason::user_shutdown);
} }
CAF_TEST(failing to deserialize a request reports an error to the sender) {
auto testee_impl = []() -> behavior {
return {
[](non_deserializable_t) { return 0; },
};
};
auto testee = earth.sys.spawn(testee_impl);
earth.sys.registry().put("testee", testee);
auto testee_proxy_ptr = mars.mm.remote_lookup("testee", earth.sys.node());
auto testee_proxy = actor_cast<actor>(testee_proxy_ptr);
mars.self->request(testee_proxy, caf::infinite, non_deserializable_t{})
.receive([](int32_t) { CAF_FAIL("Expected an error"); },
[](caf::error& err) { CHECK_EQ(err, sec::malformed_message); });
anon_send_exit(testee, exit_reason::user_shutdown);
}
END_FIXTURE_SCOPE() END_FIXTURE_SCOPE()
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