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

discovery: preserve results from other resolve calls #7886

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

GiedriusS
Copy link
Member

Properly preserve results from other resolve calls. There is an assumption that resolve() is always called with the same addresses but that is not true with gRPC and --endpoint-group. Without this fix, multiple resolves could happen at the same time but some of the callers will not be able to retrieve the results leading to random errors.

Properly preserve results from other resolve calls. There is an
assumption that resolve() is always called with the same addresses but
that is not true with gRPC and `--endpoint-group`. Without this fix,
multiple resolves could happen at the same time but some of the callers
will not be able to retrieve the results leading to random errors.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
@GiedriusS GiedriusS merged commit df3df36 into main Nov 6, 2024
22 checks passed
@GiedriusS GiedriusS deleted the endpointgroup_fix branch November 6, 2024 07:46
@@ -68,7 +73,7 @@ func (r *resolver) ResolveNow(_ grpcresolver.ResolveNowOptions) {}
func (r *resolver) resolve() error {
ctx, cancel := context.WithTimeout(r.ctx, r.interval)
defer cancel()
return r.provider.Resolve(ctx, []string{r.target})
return r.provider.Resolve(ctx, []string{r.target}, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @GiedriusS, can you please help me understand this change. This is the only place where we set it to false. Why it is the case?
Can we just enable it to true everywhere?

Copy link
Member Author

@GiedriusS GiedriusS Nov 19, 2024

Choose a reason for hiding this comment

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

No, we cannot, because in gRPC the same resolver is reused between --endpoint-groups. In other words, Build() above is called from multiple places in gRPC but they all reuse the same resolver. They first resolve and then fetch the values from cache. If we flush here then some of the results are lost and the Query component will not connected to some of the endpoints.

Some addresses can be shared between --endpoint-groups so that's why I opted to reuse the same resolver.

Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

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

@GiedriusS
I don't know if it is intended but the behavior here is different when there is a resolve error.

Let's say worst case DNS resolve for all addresses failed. The previous resolved addresses are {"A": ["1"], "B": ["2"]}. It tries to resolve addresses B and C now.

Before the change, we will have resolve results {"B": ["2"], "C": nil}.

After this change, we will have resolved results {"A": ["1"], "B": ["2"]} as it only keeps previous old records and flushOld makes no difference when there is an error.

Is this intended? I expect flushOld to only change resolved addresses when there is no error but this implementation changes the behavior with error the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants