github-actions[bot] commented on code in PR #70899:
URL: https://github.com/apache/doris/pull/70899#discussion_r4674794759


##########
be/src/service/internal_service.cpp:
##########
@@ -1237,131 +1240,137 @@ void 
PInternalServiceImpl::_get_column_ids_by_tablet_ids(
     response->mutable_status()->set_status_code(TStatusCode::OK);
 }
 
-template <class RPCResponse>
-struct AsyncRPCContext {
-    RPCResponse response;
-    brpc::Controller cntl;
-    brpc::CallId cid;
-};
+namespace {
+
+Status collect_remote_variant_schemas(const PFetchRemoteSchemaRequest& request,
+                                      std::vector<TabletSchemaSPtr>& schemas) {
+    struct SchemaRpc {
+        PFetchRemoteSchemaResponse response;
+        brpc::Controller controller;
+        std::optional<brpc::CallId> call_id;
+    };
+    PFetchRemoteSchemaRequest worker_request(request);
+    worker_request.set_is_coordinator(false);
+    std::vector<SchemaRpc> rpcs(request.tablet_location_size());
+    auto join_rpcs = [&] {
+        for (auto& rpc : rpcs) {
+            if (rpc.call_id.has_value()) {
+                brpc::Join(*rpc.call_id);
+                rpc.call_id.reset();
+            }
+        }
+    };
+    // Controllers, responses and the request must survive all dispatched RPCs 
on error too.
+    Defer join_on_exit {join_rpcs};
+    for (int i = 0; i < request.tablet_location_size(); ++i) {
+        const auto& location = request.tablet_location(i);
+        auto stub = 
ExecEnv::GetInstance()->brpc_internal_client_cache()->get_client(
+                location.host(), location.brpc_port());
+        if (stub == nullptr) {
+            return Status::InternalError("Failed to initialize remote schema 
RPC to {}:{}",
+                                         location.host(), 
location.brpc_port());
+        }
+        auto& rpc = rpcs[i];
+        
rpc.controller.set_timeout_ms(config::fetch_remote_schema_rpc_timeout_ms);
+        rpc.call_id = rpc.controller.call_id();

Review Comment:
   [P2] Avoid joining an RPC that failed before dispatch
   
   `rpc.call_id` is recorded before the stub call, so the new exit guard also 
joins it if dispatch throws. A concrete path is 
`FailureDetectChannel::CallMethod`: `new FailureDetectClosure` can throw 
`std::bad_alloc` before entering BRPC. In the pinned [BRPC 1.4.0 
controller](https://github.com/apache/brpc/blob/1.4.0/src/brpc/controller.cpp#L1179-L1196),
 `call_id()` creates a live ID; `Join()` waits for that ID to finish, while the 
[RPC 
timer](https://github.com/apache/brpc/blob/1.4.0/src/brpc/channel.cpp#L532-L543)
 is installed only after dispatch enters `Channel::CallMethod`. Unwinding 
therefore blocks in `join_on_exit` forever: the controller destructor that 
cancels the unused ID cannot run, and the outer allocation-error catch is never 
reached. FE timeout/cancellation does not release this heavy-pool worker or its 
retained RPC state. Distinguish allocated IDs from dispatched calls during 
cleanup, and cover the pre-dispatch allocation-failure path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to