-
Notifications
You must be signed in to change notification settings - Fork 963
Fix race condition when initializing HealthCheckedEndpointGroup #6188
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
a509f46
b92de35
b7e731d
018a7b1
31cbb14
d64cad0
8fcad43
3ba55fe
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -553,53 +553,57 @@ void cacheReflectsAttributeChanges() throws InterruptedException { | |||||||
final AtomicLong updateInvokedCounter = new AtomicLong(); | ||||||||
final Consumer<List<Endpoint>> endpointsListener = endpoints -> updateInvokedCounter.incrementAndGet(); | ||||||||
|
||||||||
try (HealthCheckedEndpointGroup endpointGroup = | ||||||||
new HealthCheckedEndpointGroup(delegate, true, | ||||||||
10000, 10000, | ||||||||
SessionProtocol.HTTP, 80, | ||||||||
DEFAULT_HEALTH_CHECK_RETRY_BACKOFF, | ||||||||
ClientOptions.of(), checkFactory, | ||||||||
HealthCheckStrategy.all(), | ||||||||
DEFAULT_ENDPOINT_PREDICATE)) { | ||||||||
endpointGroup.addListener(endpointsListener, true); | ||||||||
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(1)); | ||||||||
// the counter should stay 1 after 1 second has passed | ||||||||
await().pollDelay(1, TimeUnit.SECONDS) | ||||||||
.untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(1)); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR)) | ||||||||
.isFalse(); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR)) | ||||||||
.isTrue(); | ||||||||
|
||||||||
headers.set(ResponseHeaders.of(HttpStatus.OK, "x-envoy-degraded", "")); | ||||||||
// the counter should be incremented to three now | ||||||||
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(2)); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR)) | ||||||||
.isTrue(); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR)) | ||||||||
.isTrue(); | ||||||||
|
||||||||
// the counter should be incremented to two now | ||||||||
healthy.set(0); | ||||||||
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(3)); | ||||||||
assertThat(endpointGroup.endpoints()).isEmpty(); | ||||||||
|
||||||||
// healthy again | ||||||||
healthy.set(1); | ||||||||
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(4)); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR)) | ||||||||
.isTrue(); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR)) | ||||||||
.isTrue(); | ||||||||
|
||||||||
// turn off degraded again | ||||||||
headers.set(null); | ||||||||
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(5)); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR)) | ||||||||
.isTrue(); | ||||||||
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR)) | ||||||||
.isFalse(); | ||||||||
} | ||||||||
final HealthCheckedEndpointGroup endpointGroup = new HealthCheckedEndpointGroup( | ||||||||
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. Question) Shouldn't the |
||||||||
delegate, true, | ||||||||
10000, 10000, | ||||||||
SessionProtocol.HTTP, 80, | ||||||||
DEFAULT_HEALTH_CHECK_RETRY_BACKOFF, | ||||||||
ClientOptions.of(), checkFactory, | ||||||||
HealthCheckStrategy.all(), | ||||||||
DEFAULT_ENDPOINT_PREDICATE | ||||||||
); | ||||||||
|
||||||||
endpointGroup.whenReady().join(); | ||||||||
endpointGroup.addListener(endpointsListener, false); | ||||||||
endpointsListener.accept(endpointGroup.endpoints()); | ||||||||
|
endpointGroup.addListener(endpointsListener, false); | |
endpointsListener.accept(endpointGroup.endpoints()); | |
endpointGroup.addListener(endpointsListener, true); |
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.
it works ! I think Fix duplicate endpoint handling in HealthCheckedEndpointGroup
this change helps the new group include endpoints from the previous group temporarily, which avoids any brief disappearance during the transition.
Uh oh!
There was an error while loading. Please reload this page.