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

fix(registry): add timeout validation #3492

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

lftk
Copy link
Contributor

@lftk lftk commented Dec 18, 2024

使用 Consul 做服务发现时,如果 gRPC Client 的 timeout 设置为 0,程序会报错 discovery create watcher overtime

原因是:

  1. gRPC Client 会将 timeout 传给 discovery;

discovery.NewBuilder(
options.discovery,
discovery.WithInsecure(insecure),
discovery.WithTimeout(options.timeout),
discovery.WithSubset(options.subsetSize),
discovery.PrintDebugLog(options.printDiscoveryDebugLog),
)))

  1. discovery 的 Build 会因为 timeout 为 0,立马超时,得到 ErrWatcherCreateTimeout 的错误。

select {
case <-done:
err = watchRes.err
case <-time.After(b.timeout):
err = ErrWatcherCreateTimeout
}

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 18, 2024
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Dec 18, 2024
@shenqidebaozi shenqidebaozi added the bug Something isn't working label Dec 18, 2024
@shenqidebaozi
Copy link
Member

This pull request includes several changes to improve the handling of timeouts and error checking in service resolution and gRPC resolver building. The most important changes include modifications to the resolve method in contrib/registry/consul/registry.go and the Build method in transport/grpc/resolver/discovery/builder.go.

Improvements to service resolution:

Enhancements to gRPC resolver building:

  • transport/grpc/resolver/discovery/builder.go: Modified the Build method to include a conditional timeout check, ensuring that the method properly handles the timeout scenario and waits for the operation to complete if no timeout is set.

Error handling improvements in tests:

@dosubot dosubot bot added the LGTM label Dec 18, 2024
@shenqidebaozi shenqidebaozi merged commit f75bdc1 into go-kratos:main Dec 18, 2024
33 checks passed
@lftk lftk deleted the fix_registry_timeout branch December 19, 2024 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working LGTM size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants