morningman commented on code in PR #69945:
URL: https://github.com/apache/doris/pull/69945#discussion_r4442622525


##########
be/test/service/arrow_flight/arrow_flight_cancel_test.cpp:
##########
@@ -0,0 +1,410 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <arrow/flight/client.h>
+#include <arrow/flight/sql/server.h>
+#include <brpc/server.h>
+#include <gtest/gtest.h>
+
+#include <future>
+#include <thread>
+
+#include "exec/pipeline/dependency.h"
+#include "load/channel/load_stream_mgr.h"
+#include "runtime/result_buffer_mgr.h"
+#include "service/arrow_flight/arrow_flight_batch_reader.h"
+#include "service/arrow_flight/flight_sql_service.h"
+#include "service/backend_options.h"
+#include "service/internal_service.h"
+#include "testutil/column_helper.h"
+#include "testutil/mock/mock_runtime_state.h"
+#include "util/brpc_client_cache.h"
+#include "util/debug/leakcheck_disabler.h"
+#include "util/dns_cache.h"
+
+namespace doris::flight {
+
+class ArrowFlightCancelTest : public testing::Test {
+protected:
+    void SetUp() override {
+        _previous_mgr = std::exchange(ExecEnv::GetInstance()->_result_mgr, 
&_mgr);
+        _state._batch_size = 1;
+        _id.hi = 1;
+        _id.lo = 2;
+        auto schema = arrow::schema({arrow::field("value", arrow::int64())});
+        std::shared_ptr<ResultBlockBufferBase> buffer;
+        ASSERT_TRUE(_mgr.create_sender(_id, 16, &buffer, &_state, true, 
schema).ok());
+        _buffer = 
std::dynamic_pointer_cast<ArrowFlightResultBlockBuffer>(buffer);
+        _dep = Dependency::create_shared(0, 0, "Result", true);
+        _buffer->set_dependency(_state.fragment_instance_id(), _dep);
+        TNetworkAddress address;
+        address.hostname = BackendOptions::get_localhost();
+        address.port = config::brpc_port;
+        _statement = std::make_shared<QueryStatement>(_id, address, "select 
value");
+    }
+    void TearDown() override { ExecEnv::GetInstance()->_result_mgr = 
_previous_mgr; }
+    void fill_buffer() {
+        auto block = 
std::make_shared<Block>(ColumnHelper::create_block<DataTypeInt64>({1, 2}));
+        ASSERT_TRUE(_buffer->add_batch(&_state, block).ok());
+        ASSERT_FALSE(_dep->ready());
+    }
+    bool registered() {
+        std::shared_ptr<ArrowFlightResultBlockBuffer> found;
+        return _mgr.find_buffer(_id, found).ok();
+    }
+    MockRuntimeState _state;
+    ResultBufferMgr _mgr;

Review Comment:
   Fixed in e5736f55c0f. `ArrowFlightCancelTest::TearDown()` now calls 
`_mgr.stop()` after restoring the previous `ExecEnv::_result_mgr`, so the 
`result_buffer_block_count` hook and its gauge are deregistered before the 
fixture destroys the manager, the same way `LoadChannelMgrTest::TearDown()` 
stops its `LoadChannelMgr`. The fixture never calls `init()`, so `stop()` has 
no cleaner thread to join. Each fixture now registers its own hook and removes 
it again, so a later fixture no longer finds a stale one; 
`ArrowFlightRemoteCancelTest` gets the same cleanup through 
`ArrowFlightCancelTest::TearDown()`.
   
   On the impact: nothing in `doris_be_test` runs the server entity's hooks 
today. `enable_metric_calculator` defaults to true, so `to_prometheus()` and 
`to_json()` skip the hooks, and the daemon thread that calls 
`trigger_all_hooks(true)` is not started in UT. So this was latent, not an 
observed use-after-free. `ResultBufferMgrTest` on master builds six managers on 
the stack in the same way and never stops them; that file is outside this PR.
   



-- 
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