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 the problem of configuring multiple gRPC endpoints where the first endpoint times out and cannot switch to the second endpoint #14144

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ git_repository(
# gazelle args: -go_prefix github.com/gogo/protobuf -proto legacy
)

git_repository(
name = "org_golang_google_grpc",
commit = "1055b481ed2204a29d233286b9b50c42b63f8825",
patch_args = ["-p1"],
patches = [
"//third_party:org_golang_google_grpc_clientconn.patch",
],
remote = "https://github.com/grpc/grpc-go",
)

load("@rules_oci//oci:pull.bzl", "oci_pull")

# A multi-arch base image
Expand Down
41 changes: 41 additions & 0 deletions third_party/org_golang_google_grpc_clientconn.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/clientconn.go b/clientconn.go
index 95a7459b..a7acdabc 100644
--- a/clientconn.go
+++ b/clientconn.go
@@ -1323,18 +1323,11 @@ func (ac *addrConn) resetTransport() {
// Give dial more time as we keep failing to connect.
dialDuration = backoffFor
}
- // We can potentially spend all the time trying the first address, and
- // if the server accepts the connection and then hangs, the following
- // addresses will never be tried.
- //
- // The spec doesn't mention what should be done for multiple addresses.
- // https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md#proposed-backoff-algorithm
- connectDeadline := time.Now().Add(dialDuration)

ac.updateConnectivityState(connectivity.Connecting, nil)
ac.mu.Unlock()

- if err := ac.tryAllAddrs(acCtx, addrs, connectDeadline); err != nil {
+ if err := ac.tryAllAddrs(acCtx, addrs, dialDuration); err != nil {
ac.cc.resolveNow(resolver.ResolveNowOptions{})
// After exhausting all addresses, the addrConn enters
// TRANSIENT_FAILURE.
@@ -1377,7 +1370,7 @@ func (ac *addrConn) resetTransport() {
// tryAllAddrs tries to creates a connection to the addresses, and stop when at
// the first successful one. It returns an error if no address was successfully
// connected, or updates ac appropriately with the new transport.
-func (ac *addrConn) tryAllAddrs(ctx context.Context, addrs []resolver.Address, connectDeadline time.Time) error {
+func (ac *addrConn) tryAllAddrs(ctx context.Context, addrs []resolver.Address, dialDuration time.Duration) error {
var firstConnErr error
for _, addr := range addrs {
if ctx.Err() != nil {
@@ -1397,6 +1390,7 @@ func (ac *addrConn) tryAllAddrs(ctx context.Context, addrs []resolver.Address, c

channelz.Infof(logger, ac.channelzID, "Subchannel picks a new address %q to connect", addr.Addr)

+ connectDeadline := time.Now().Add(dialDuration)
err := ac.createTransport(ctx, addr, copts, connectDeadline)
if err == nil {
return nil
Loading