Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rd-cpp] Fixed issues with access to released bounded call results #464

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions rd-cpp/src/rd_framework_cpp/src/main/task/RdEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,29 @@ class RdEndpoint : public virtual RdReactiveBase, public ISerializable
{
throw std::invalid_argument("handler is empty for RdEndPoint");
}
auto task = awaiting_tasks[task_id] = {};

using TaskResult = RdTaskResult<TRes, ResSer>;

auto lifetime = *bind_lifetime;
auto send_result = [this, task_id](TaskResult const& task_result)
{
auto logger = spdlog::get("logSend");
if (logger->should_log(spdlog::level::trace))
logger->trace("endpoint {}::{} response = {}", to_string(location), to_string(rdid), to_string(task_result));
get_wire()->send(task_id, [&](Buffer& inner_buffer) { task_result.write(get_serialization_context(), inner_buffer); });
};

try
{
task = local_handler(*bind_lifetime, wrapper::get<TReq>(value));
auto task = local_handler(lifetime, wrapper::get<TReq>(value));
awaiting_tasks[task_id] = task;
lifetime->add_action([this, task_id] { awaiting_tasks.erase(task_id); });
task.advise(lifetime, send_result);
}
catch (std::exception const& e)
{
task.fault(e);
send_result(typename TaskResult::Fault(e));
}
task.advise(*bind_lifetime,
[this, task_id, &task](RdTaskResult<TRes, ResSer> const& task_result)
{
spdlog::get("logSend")->trace(
"endpoint {}::{} response = {}", to_string(location), to_string(rdid), to_string(*task.result));
get_wire()->send(
task_id, [&](Buffer& inner_buffer) { task_result.write(get_serialization_context(), inner_buffer); });
// TO-DO remove from awaiting_tasks
});
}

friend bool operator==(const RdEndpoint& lhs, const RdEndpoint& rhs)
Expand Down
Loading