Regression test for IMPALA-8270: MemTracker teardown order leading to use-after-free from LogUsage.
| 34 | // Regression test for IMPALA-8270: MemTracker teardown order leading to |
| 35 | // use-after-free from LogUsage. |
| 36 | TEST(RuntimeStateTest, MemTrackerTeardown) { |
| 37 | const int LOG_USAGE_THREADS = 4; |
| 38 | const int CONSTRUCT_ITERS = 10; |
| 39 | TestEnv test_env; |
| 40 | ASSERT_OK(test_env.Init()); |
| 41 | // Poll LogUsage() from other threads to reproduce race. |
| 42 | AtomicBool stop_threads(false); |
| 43 | thread_group log_usage_threads; |
| 44 | for (int i = 0; i < LOG_USAGE_THREADS; ++i) { |
| 45 | log_usage_threads.add_thread(new thread([&test_env, &stop_threads]() { |
| 46 | while (!stop_threads.Load()) { |
| 47 | string usage = test_env.exec_env()->process_mem_tracker()->LogUsage(100); |
| 48 | } |
| 49 | })); |
| 50 | } |
| 51 | |
| 52 | // Construct and tear down RuntimeState repeatedly to try to reproduce race. |
| 53 | for (int i = 0; i < CONSTRUCT_ITERS; ++i) { |
| 54 | TQueryCtx query_ctx; |
| 55 | unique_ptr<RuntimeState> state(new RuntimeState(query_ctx, test_env.exec_env())); |
| 56 | ASSERT_TRUE(state->instance_mem_tracker() != nullptr); |
| 57 | state->ReleaseResources(); |
| 58 | state.reset(); |
| 59 | } |
| 60 | stop_threads.Store(true); |
| 61 | log_usage_threads.join_all(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | int main(int argc, char** argv) { |
nothing calls this directly
no test coverage detected