Skip to content
Merged
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
19 changes: 18 additions & 1 deletion utils/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ limitations under the License.
package utils

import (
"context"
"fmt"
"net"
"net/url"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
)

// Connect address by grpc
Expand All @@ -38,5 +41,19 @@ func Connect(address string) (*grpc.ClientConn, error) {
}))
}

return grpc.Dial(address, dialOptions...)
conn, err := grpc.Dial(address, dialOptions...)
if err != nil {
return nil, err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
for {
if !conn.WaitForStateChange(ctx, conn.GetState()) {
return conn, fmt.Errorf("Connection timed out")
}
if conn.GetState() == connectivity.Ready {
return conn, nil
}
}
}