-
Notifications
You must be signed in to change notification settings - Fork 499
Fix suspend race cond #2167
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
Fix suspend race cond #2167
Conversation
422b974 to
ad3f796
Compare
|
Build FAILURE |
lib/early_ack_tracker.c
Outdated
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.
log_source_wakeup is unnecessary here. log_source_flow_control_adjust should schedule the wakeup based on its knowledge (window size + suspend bit).
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.
I think after my change it's not...
Maybe it's a wrong direction but trying to make suspend/wakeup more symmetrical:
suspend bit is set by suspend and unset by wakeup...
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.
I made a small change:
- suspend is set by
log_source_flow_control_suspend - suspend is unset by
log_source_wakeup free_to_sendblocks reading until suspend bit is set or the window size is 0- when window size was 0 before
log_source_flow_control_adjustis called, then we calllog_source_wakeup - when ack_tracker receives an ACK, then it checks if source is suspended or not (and based on the acknowledge type it makes a decision whether we need to suspend/wakeup the source)
lib/late_ack_tracker.c
Outdated
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.
log_source_wakeup is unnecessary here. log_source_flow_control_adjust should schedule the wakeup based on its knowledge (window size + suspend bit).
lib/logsource.c
Outdated
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.
The new (incremented) window size should be used here instead of the old one.
Instead of calling window_size_counter_get here, we could write old_window_size + window_size_increment == ... which is guaranteed to preserve the value of the previous window_size_counter_add call (preserves atomicity).
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.
yes, you are right
lib/logsource.c
Outdated
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.
I would not add this condition to log_source_wakeup.
The name of this function tells me that it will wake the source up without condition.
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.
well... someone should check this suspend bit...
This is not the best and not the final place (this is why I added the wip flag :) )
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.
Oops, okay, sorry. I'll check it.
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.
I'm also playing with this a little bit.
|
Build FAILURE |
ce03904 to
2a676d0
Compare
|
Build FAILURE |
2a676d0 to
47c3259
Compare
|
Build FAILURE |
1 similar comment
|
Build FAILURE |
|
Build SUCCESS |
lib/atomic-gssize.h
Outdated
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.
I'd remove these 3 racy operations. We had only problems with them in the past.
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.
...and I would not, not part of this PR. I agree with you that we should consider to remove all the racy atomic operations, but... but I also know that I don't want to discuss it it as part of this PR.
This is why I wanted to atomic-gssize PR handled separately. Please, add these notes to there, or, after that PR merged, we could open a new PR where we remove all these operations and explain why we don't need them anymore.
If no other issues, don't forget to approve the requested changes :)
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.
Okay. I've added my comment to #2159.
a298db9 to
dfd022b
Compare
|
Build SUCCESS |
lib/ack_tracker.h
Outdated
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.
I think we should not check free_to_send() here. We might skip suspend() while another thread is waking up the source.
lib/ack_tracker.h
Outdated
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.
The free_to_send() call is a problem here too.
Instead of calling wakeup here, I would reset the suspend bit in _flow_control_window_size_adjust(), where we can do it safely.
|
Build FAILURE |
178af2d to
b8fc53a
Compare
|
Build SUCCESS |
lib/window-size-counter.c
Outdated
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.
atomic_gssize is implemented with atomic pointers, so I would add a static_assert to compare its size with gsize if we want to use G_MAXSIZE on it.
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.
added
lib/window-size-counter.c
Outdated
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.
Should not it be 1ULL << ...? I think the cast would be unnecessary this way.
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.
Wouldn't be the type of the expression unsigned long long? I'd stick to the gsize type.
lib/logsource.c
Outdated
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.
Would you like to leave this debug message in the final patch?
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.
Well.. I found it very useful during development... but it is possible to print out a better message, I'll try to do that. But I'd keep a debug message here.
lib/logsource.c
Outdated
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.
Please consider adding this new evt tag to log_source_flow_control_suspend as well. We have the same debug message there.
I don't know about our evt tag conventions, but it seems we prefer lowercase tag names (function vs. Function).
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.
ok, will check it.
|
@kira-syslogng do perftest |
|
Build SUCCESS |
b8fc53a to
5f43934
Compare
|
Build FAILURE |
5f43934 to
7c17cc7
Compare
|
Build SUCCESS |
This is an atomic counter for tracking window size and suspend state. On 64 bit systems the max. window size is 2^63-1, while on 32 bit systems 2^31-1. Code asserts in case of overflow/underflow. Signed-off-by: Laszlo Budai <[email protected]>
7c17cc7 to
fe7c692
Compare
A window-size leak also fixed: when ack_type is AT_SUSPENDED, we have to count the window size even if there is no continuous range in ringbuffer. Signed-off-by: Laszlo Budai <[email protected]>
fe7c692 to
d5dc3bd
Compare
|
Build SUCCESS |
1 similar comment
|
Build SUCCESS |
MrAnno
left a comment
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.
🔲 (This is a window.)
@MrAnno : please check whether it supersedes #2045 or not.
log_source_flow_control_suspendlog_source_wakeupfree_to_sendblocks reading until suspend bit is set or the window size is 0log_source_flow_control_adjustis called, then we calllog_source_wakeup