Skip to content

Commit 5361421

Browse files
authored
[k2] fix exception handling in wait_multi and some other minor fixes (#1526)
* check iterators before erase in RPC API * add missing fetch_float and can_throw attributes * fix exception handling in wait_multi
1 parent dc5621a commit 5361421

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

builtin-functions/kphp-light/stdlib/rpc.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ function fetch_byte () ::: int;
7676
/** @kphp-extern-func-info can_throw */
7777
function fetch_long () ::: int;
7878

79+
/** @kphp-extern-func-info can_throw */
80+
function fetch_float () ::: float;
81+
7982
/** @kphp-extern-func-info can_throw */
8083
function fetch_double () ::: float;
8184

builtin-functions/kphp-light/stdlib/vkext-functions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function vk_whitespace_pack ($str ::: string, $html_opt ::: bool = false) ::: st
1818

1919
function vk_sp_full_simplify ($str ::: string) ::: string;
2020

21+
/** @kphp-extern-func-info can_throw */
2122
function vk_json_encode_safe ($v ::: mixed) ::: string;
2223

2324
function vk_stats_hll_merge($str ::: mixed) ::: string | false;

runtime-light/stdlib/fork/fork-functions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "runtime-light/coroutine/shared-task.h"
1919
#include "runtime-light/coroutine/task.h"
2020
#include "runtime-light/coroutine/type-traits.h"
21+
#include "runtime-light/stdlib/diagnostics/exception-functions.h"
2122
#include "runtime-light/stdlib/diagnostics/logs.h"
2223
#include "runtime-light/stdlib/fork/fork-state.h"
2324
#include "runtime-light/stdlib/fork/fork-storage.h"
@@ -145,7 +146,7 @@ template<typename T>
145146
kphp::coro::task<T> f$wait_multi(array<int64_t> fork_ids) noexcept {
146147
T res{};
147148
for (const auto& it : std::as_const(fork_ids)) {
148-
res.set_value(it.get_key(), co_await f$wait<typename T::value_type>(it.get_value()));
149+
res.set_value(it.get_key(), TRY_CALL_CORO(typename T::value_type, T, co_await f$wait<typename T::value_type>(it.get_value())));
149150
}
150151
co_return std::move(res);
151152
}

runtime-light/stdlib/rpc/rpc-api.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,12 @@ kphp::coro::task<array<mixed>> rpc_tl_query_result_one_impl(int64_t query_id) no
183183
const auto it_response_fetcher{rpc_client_instance_st.response_fetcher_instances.find(query_id)};
184184
const auto it_fork_task{rpc_client_instance_st.response_awaiter_tasks.find(query_id)};
185185
const vk::final_action finalizer{[&rpc_client_instance_st, it_response_fetcher, it_fork_task] noexcept {
186-
rpc_client_instance_st.response_fetcher_instances.erase(it_response_fetcher);
187-
rpc_client_instance_st.response_awaiter_tasks.erase(it_fork_task);
186+
if (it_response_fetcher != rpc_client_instance_st.response_fetcher_instances.end()) [[likely]] {
187+
rpc_client_instance_st.response_fetcher_instances.erase(it_response_fetcher);
188+
}
189+
if (it_fork_task != rpc_client_instance_st.response_awaiter_tasks.end()) [[likely]] {
190+
rpc_client_instance_st.response_awaiter_tasks.erase(it_fork_task);
191+
}
188192
}};
189193

190194
if (it_response_fetcher == rpc_client_instance_st.response_fetcher_instances.end() || it_fork_task == rpc_client_instance_st.response_awaiter_tasks.end())
@@ -236,8 +240,12 @@ kphp::coro::task<class_instance<C$VK$TL$RpcResponse>> typed_rpc_tl_query_result_
236240
const auto it_response_fetcher{rpc_client_instance_st.response_fetcher_instances.find(query_id)};
237241
const auto it_fork_task{rpc_client_instance_st.response_awaiter_tasks.find(query_id)};
238242
const vk::final_action finalizer{[&rpc_client_instance_st, it_response_fetcher, it_fork_task] noexcept {
239-
rpc_client_instance_st.response_fetcher_instances.erase(it_response_fetcher);
240-
rpc_client_instance_st.response_awaiter_tasks.erase(it_fork_task);
243+
if (it_response_fetcher != rpc_client_instance_st.response_fetcher_instances.end()) [[likely]] {
244+
rpc_client_instance_st.response_fetcher_instances.erase(it_response_fetcher);
245+
}
246+
if (it_fork_task != rpc_client_instance_st.response_awaiter_tasks.end()) [[likely]] {
247+
rpc_client_instance_st.response_awaiter_tasks.erase(it_fork_task);
248+
}
241249
}};
242250

243251
if (it_response_fetcher == rpc_client_instance_st.response_fetcher_instances.end() || it_fork_task == rpc_client_instance_st.response_awaiter_tasks.end())

0 commit comments

Comments
 (0)