-
Notifications
You must be signed in to change notification settings - Fork 438
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
[SDK] Fix forceflush may wait for ever #2584
[SDK] Fix forceflush may wait for ever #2584
Conversation
…in critical section.
@ThomsonTan Is there any problem in this PR? Maybe we can close #2553 if this PR is merged. It fixes the same problems as #2553 do and also fix the simular problems in trace and logs. |
sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h
Outdated
Show resolved
Hide resolved
sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h
Outdated
Show resolved
Hide resolved
@@ -79,21 +79,25 @@ bool BatchLogRecordProcessor::ForceFlush(std::chrono::microseconds timeout) noex | |||
// Now wait for the worker thread to signal back from the Export method | |||
std::unique_lock<std::mutex> lk_cv(synchronization_data_->force_flush_cv_m); | |||
|
|||
synchronization_data_->is_force_flush_pending.store(true, std::memory_order_release); | |||
std::uint64_t current_sequence = | |||
synchronization_data_->force_flush_pending_sequence.fetch_add(1, std::memory_order_release) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the fetch_add here just the same as synchronization_data_->force_flush_pending_sequence++
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding, synchronization_data_->force_flush_pending_sequence++
use std::memory_order_seq_cst
, we can use std::memory_order_release
here.
BTW, can you explain in brief that why the sequence notification can break the potential forever wait? Thanks. |
When more than one threads call |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2584 +/- ##
==========================================
+ Coverage 87.12% 87.70% +0.58%
==========================================
Files 200 190 -10
Lines 6109 5852 -257
==========================================
- Hits 5322 5132 -190
+ Misses 787 720 -67
|
…en_calling_forceflush
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix.
This area also changed recently when is_shutdown was fixed to be an atomic instead of a plain boolean.
I was concerned with potential overlap and collisions, but it turns out the two fixes are really independent, which is better.
LGTM.
[SDK] Fix forceflush may wait for ever (open-telemetry#2584)
Fixes #2574
May also fixes #2583
Changes
ForceFlush
.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes