Skip to content
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

Keep only the latest value in the health channel #14087

Merged
merged 4 commits into from
Jun 6, 2024

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Jun 6, 2024

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

#14033 introduced a subtle race condition. The channel has a buffer size of 1. Previously we unlocked before sending to the channel. This means that if we tried to send a second value, sending to the channel blocked but any other function that required the lock could take it. In the current version this other function will need to wait for the lock. And that's what happened with the REST VC. I don't know how exactly it got to this, but apparently a second value was sent to the channel before reading the first one, which captured the lock. Another function tried to obtain the lock, and reading the first value from the channel depended on this function returning.

To fix this, we introduce a switch statement that always replaces the existing value in the channel with a new one.

@rkapka rkapka requested a review from a team as a code owner June 6, 2024 17:30
@rkapka rkapka changed the title Increase health tracker channel buffer size Keep only the latest value in the health channel Jun 6, 2024
@@ -87,12 +87,6 @@ func TestNodeHealth_Concurrency(t *testing.T) {
// Number of goroutines to spawn for both reading and writing
numGoroutines := 6

go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the regression test to show that CheckHealth is non-blocking

Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@prestonvanloon prestonvanloon added this pull request to the merge queue Jun 6, 2024
Copy link
Contributor

@james-prysm james-prysm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Merged via the queue into develop with commit 8413660 Jun 6, 2024
16 of 17 checks passed
@prestonvanloon prestonvanloon deleted the increase-health-chan branch June 6, 2024 18:52
prestonvanloon added a commit that referenced this pull request Jun 10, 2024
* Increase health tracker channel buffer size

* keep only the latest value

* Make health test blocking as a regression test for PR #14807

* Fix new race conditions in the MockHealthClient

---------

Co-authored-by: Preston Van Loon <preston@pvl.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants