-
Notifications
You must be signed in to change notification settings - Fork 625
[BUG] Prevent lost condition-variable wakeups during OTLP file, periodic metric, and batch span processor shutdown #4365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e35bb01
6551f60
b28f264
255f810
c2e05e4
6b7a1db
18f3bd4
f39c117
ad6e820
ca42402
b9c7dd5
be2890a
77e897a
c5c48b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,7 +221,12 @@ bool PeriodicExportingMetricReader::OnForceFlush(std::chrono::microseconds timeo | |
| if (force_flush_pending_sequence_.load(std::memory_order_acquire) > | ||
| force_flush_notified_sequence_.load(std::memory_order_acquire)) | ||
| { | ||
| is_force_wakeup_background_worker_.store(true, std::memory_order_release); | ||
| { | ||
| // Acquiring cv_m_ guarantees that the worker thread either is not currently waiting on cv_, | ||
| // or the notify below will cause it to re-check the wait condition. | ||
| std::lock_guard<std::mutex> cv_guard{cv_m_}; | ||
| is_force_wakeup_background_worker_.store(true, std::memory_order_release); | ||
| } | ||
| cv_.notify_all(); | ||
| } | ||
| return force_flush_notified_sequence_.load(std::memory_order_acquire) >= current_sequence; | ||
|
|
@@ -283,6 +288,11 @@ bool PeriodicExportingMetricReader::OnShutDown(std::chrono::microseconds timeout | |
| { | ||
| if (worker_thread_.joinable()) | ||
| { | ||
| { | ||
| // Acquiring cv_m_ guarantees that the next time the worker thread checks the wait condition | ||
| // on cv_ (either from notify below or any other reason) it will see IsShutdown() return true. | ||
| std::lock_guard<std::mutex> cv_guard{cv_m_}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fence is right, the wait predicate checks
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's in the same vein, I've added the change to ForceFlush as well.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ForceFlush change looks right, and no lock-order problem with it: this path takes One direction is still open though. This fixes the waker side ( |
||
| } | ||
| cv_.notify_all(); | ||
| worker_thread_.join(); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.