From 02a86d2215ad0b8cf7bd6dab8587b0bfd5ee10ec Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 11 Nov 2022 14:16:18 +0800 Subject: [PATCH] [Bug](runtimefilter) Fix concurrent bug in runtime filter #14177 For runtime filter, signal will be called by a thread which is different from the await thread. So there will be a potential race for variable is_ready --- be/src/exprs/runtime_filter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/be/src/exprs/runtime_filter.cpp b/be/src/exprs/runtime_filter.cpp index b0e8f3d1ba..88d2507d3b 100644 --- a/be/src/exprs/runtime_filter.cpp +++ b/be/src/exprs/runtime_filter.cpp @@ -1230,13 +1230,13 @@ bool IRuntimeFilter::await() { DCHECK(is_consumer()); SCOPED_TIMER(_await_time_cost); int64_t wait_times_ms = _state->runtime_filter_wait_time_ms(); + std::unique_lock lock(_inner_mutex); if (!_is_ready) { int64_t ms_since_registration = MonotonicMillis() - registration_time_; int64_t ms_remaining = wait_times_ms - ms_since_registration; if (ms_remaining <= 0) { return _is_ready; } - std::unique_lock lock(_inner_mutex); return _inner_cv.wait_for(lock, std::chrono::milliseconds(ms_remaining), [this] { return this->_is_ready; }); } @@ -1245,6 +1245,7 @@ bool IRuntimeFilter::await() { void IRuntimeFilter::signal() { DCHECK(is_consumer()); + std::unique_lock lock(_inner_mutex); _is_ready = true; _inner_cv.notify_all();