|
17 | 17 | #include "runtime-common/core/std/containers.h" |
18 | 18 | #include "runtime-light/core/globals/php-init-scripts.h" |
19 | 19 | #include "runtime-light/core/globals/php-script-globals.h" |
| 20 | +#include "runtime-light/coroutine/await-set.h" |
20 | 21 | #include "runtime-light/coroutine/task.h" |
21 | 22 | #include "runtime-light/k2-platform/k2-api.h" |
22 | 23 | #include "runtime-light/server/cli/init-functions.h" |
|
27 | 28 | #include "runtime-light/stdlib/diagnostics/logs.h" |
28 | 29 | #include "runtime-light/stdlib/fork/fork-functions.h" |
29 | 30 | #include "runtime-light/stdlib/fork/fork-state.h" |
| 31 | +#include "runtime-light/stdlib/rpc/rpc-client-state.h" |
30 | 32 | #include "runtime-light/stdlib/time/time-functions.h" |
31 | 33 | #include "runtime-light/streams/read-ext.h" |
32 | 34 | #include "runtime-light/streams/stream.h" |
@@ -214,4 +216,22 @@ kphp::coro::task<> InstanceState::run_instance_epilogue() noexcept { |
214 | 216 | web_state.session_is_finished = true; |
215 | 217 | web_state.session.reset(); |
216 | 218 | } |
| 219 | + |
| 220 | + /* |
| 221 | + * Unlike regular RPC requests whose results the user code waits for via rpc_fetch_responses, |
| 222 | + * thereby guaranteeing they are sent, the user code does not wait for requests sent with the |
| 223 | + * ignore_answer flag. Therefore, we can’t guarantee that the coroutines responsible for |
| 224 | + * sending ignore_answer requests have finished. This means the requests might not be sent |
| 225 | + * if the instance terminates. |
| 226 | + * |
| 227 | + * This await suspends the current coroutine until all pending ignore_answer requests are |
| 228 | + * fully sent. While suspended, other forks and coroutines may continue running. |
| 229 | + * |
| 230 | + * After this call completes, delivery of all ignore_answer requests is guaranteed. |
| 231 | + */ |
| 232 | + auto& rpc_client_instance_st{RpcClientInstanceState::get()}; |
| 233 | + auto ignore_answer_request_await_set{std::exchange(rpc_client_instance_st.ignore_answer_request_awaiter_tasks, kphp::coro::await_set<void>{})}; |
| 234 | + while (!ignore_answer_request_await_set.empty()) { |
| 235 | + co_await ignore_answer_request_await_set.next(); |
| 236 | + } |
217 | 237 | } |
0 commit comments